[Swift-user] @tostring?

Justin M Wozniak wozniak at mcs.anl.gov
Mon Apr 5 10:11:19 CDT 2010


On Sat, 27 Mar 2010, wilde at mcs.anl.gov wrote:

> (3) Justin has added an @java() primitive to the development trunk; so 
> if there's a Java method among standard or Swift Java classes that you 
> can call to do a needed string operation, that may be useful. I cant 
> recall if that was posted to one of the lists or not.

Sorry for the delay.

Here is the link to the @java note:

http://mail.ci.uchicago.edu/pipermail/swift-user/2010-March/001382.html

Also, I implemented an @tostring() back when I thought @strcat() was 
typechecked.  You can try that if you want.

> === (1) - A "toy" Swift library:
>
> // General Swift Lib Functions
>
> app (file o) echoi (int i)     { echo i stdout=@o;}
> app (file o) echof (float f)   { echo f stdout=@o;}
> app (file o) echob (boolean b) { echo b stdout=@o;}
> app (file o) echos (string s)  { echo s stdout=@o;}
>
> (string s) itostr (int i)
> {
>  file f;
>  f = echoi(i);
>  s = readData(f);
> }
>
> (string s) ftostr (float n)
> {
>  file f;
>  f = echof(n);
>  s = readData(f);
> }
>
> (int n) strtoi (string s)
> {
>  file f;
>  f = echos(s);
>  n = readData(f);
> }
>
> (float n) strtof (string s)
> {
>  file f;
>  f = echos(s);
>  n = readData(f);
> }
>
> app (file o) sprintfsApp (string fmt, string e[])
> {
>  sprintfs fmt e stdout=@o;
> }
>
> (string s) sprintfs (string fmt, string e[])
> {
>  file f;
>  f = sprintfsApp(fmt,e);
>  s = readData(f);
> }
>
> === (2) swiftshell:
>
> login1$ more shelldemo.swift swiftshell
> ::::::::::::::
> shelldemo.swift
> ::::::::::::::
> type file;
>
> app (file o) cat (file i)
> {
>  shell " ( cat " @i "; date; hostname ) | grep . " stdout=@o;
> }
>
> file data<"data.txt">;
> file out<"out.txt">;
> out = cat(data);
> ::::::::::::::
> swiftshell
> ::::::::::::::
> bash -c "$*"
> login1$ grep shell tc
> localhost 	shell	/home/wilde/swift/lab/swiftshell	null	null	null
> mcs	 	shell	/home/wilde/swift/lab/swiftshell	null	null	null
> login1$
>
> === (3) @java()
>
> Justin previously posted this to the list:
>
> "         If you can check out the latest Swift from trunk I've added some
> features that might help you out here.  There's a new built-in function @java()
> that allows you to call into an existing Java library.  You can call into the
> Java Platform or into your CLASSPATH.
>         Here is one example:
>
> (float result) sin(float x) {
>   result = @java("java.lang.Math", "sin", x);
> }
>
> float x = 0.5;
> float y = sin(x);
>
> trace("sin", x, y);
>
> Note that you currently have to assign the result of @java() to a variable."
>
>
>
>
> ----- "Andriy Fedorov" <fedorov at bwh.harvard.edu> wrote:
>
>> On Sat, Mar 27, 2010 at 17:34, Michael Wilde <wilde at mcs.anl.gov>
>> wrote:
>>> Andriy, Im pretty sure @strcat() will take an int and return a
>> string.
>>>
>>
>> Mike, yes, you are right -- there was another error in my script,
>> @strcat indeed works with int.
>>
>> One more basic question (sorry if I missed this in the guide): is
>> there a way to get the size of an array? I would like to split a
>> string, and get the last item in the array it returns. Is this
>> possible?
>>
>>
>>> - Mike
>>>
>>> ----- "Andriy Fedorov" <fedorov at bwh.harvard.edu> wrote:
>>>
>>>> Hi,
>>>>
>>>> Is it possible to convert int type to string type in Swift?
>>>>
>>>> I see @toint, but not @tostring, and it looks like I am not able
>> to
>>>> pass int to @strcat().
>>>>
>>>> Thanks
>>>>
>>>> --
>>>> Andriy Fedorov, Ph.D.
>>>>
>>>> Research Fellow
>>>> Brigham and Women's Hospital
>>>> Harvard Medical School
>>>> 75 Francis Street
>>>> Boston, MA 02115 USA
>>>> fedorov at bwh.harvard.edu
>>>> _______________________________________________
>>>> Swift-user mailing list
>>>> Swift-user at ci.uchicago.edu
>>>> http://mail.ci.uchicago.edu/mailman/listinfo/swift-user
>>>
>>> --
>>> Michael Wilde
>>> Computation Institute, University of Chicago
>>> Mathematics and Computer Science Division
>>> Argonne National Laboratory
>>>
>>>
>
>

-- 
Justin M Wozniak



More information about the Swift-user mailing list