Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'pass String patterns in arguments of Compile' topicStudent Support Forum > General > Archives > "pass String patterns in arguments of Compile"

Next Comment >Help | Reply To Topic
Author Comment/Response
Bishshoy Das
02/20/12 3:19pm

I am trying to run this code:

In[1]:= fn[arg_] := StringLength[ToString[arg]]
In[2]:= fn[abcd]
Out[2]= 4
In[4]:= fnc = Compile[{arg},StringLength[ToString[arg]]]
Out[4]= CompiledFunction[{arg},StringLength[ToString[arg]],-CompiledCode-]
In[5]:= fnc[abcd]
During evaluation of In[5]:= CompiledFunction::cfsa: Argument abcd at position 1 should be a machine-size real number. >>
Out[5]= 4

For the compiled version of the same function, I get an error. Please help me correct this. Also I would like to know if there is anyway I can pass String arguments to any Compiled Functions directly without using ToString[_Symbol] override. Thank you.

URL: ,

Subject (listing for 'pass String patterns in arguments of Compile')
Author Date Posted
pass String patterns in arguments of Compile Bishshoy Das 02/20/12 3:19pm
Re: pass String patterns in arguments of Compile toen 02/22/12 10:00am
Re: pass String patterns in arguments of Compile Bishshoy Das 02/23/12 3:38pm
Next Comment >Help | Reply To Topic