Where does the output go?

10 views
Skip to first unread message

WyattBiker

unread,
Sep 5, 2009, 1:49:40 PM9/5/09
to F-Script
"seems to work but no answer"
{'one', 'two', 'three'} do:[:each| each printString]

" this answers"
'one' printString

Ken Ferry

unread,
Sep 5, 2009, 2:29:25 PM9/5/09
to f-sc...@googlegroups.com
This does not compile for me as F-Script.  There is no -do:.  

If F-Script this would be written as 

    {'one', 'two', 'three'} @ printString

and the @ is optional.  You'd get the result returned and displayed in the console.

See the section "Smalltalk collection protocols & F-Script" in the F-Script guide.

-Ken

WyattBiker

unread,
Sep 5, 2009, 3:15:53 PM9/5/09
to F-Script
Sure there is a #do:. It's executing, just not printing. The @ is cool
but I prefer not to use it unless I have to. Too much like perl or
ruby.

Here is #do:

> zz:={1,2,3}
> xx:=0
> zz do: [:yy | xx:=xx+yy]
> xx
6


On Sep 5, 2:29 pm, Ken Ferry <kenfe...@gmail.com> wrote:
> This does not compile for me as F-Script.  There is no -do:.
> If F-Script this would be written as
>
>     {'one', 'two', 'three'} @ printString
>
> and the @ is optional.  You'd get the result returned and displayed in the
> console.
>
> See the section "Smalltalk collection protocols & F-Script" in the F-Script
> guide.
>
> -Ken
>

Ken Ferry

unread,
Sep 5, 2009, 3:28:51 PM9/5/09
to f-sc...@googlegroups.com

On Sat, Sep 5, 2009 at 12:15 PM, WyattBiker <wyatt...@gmail.com> wrote:

Sure there is a #do:.

Not in my interpreter!  Are you sure you didn't link in something that added it?  Either that or it was added recently and I don't have the current version installed as thoroughly as I thought..
 
It's executing, just not printing. The @ is cool
but I prefer not to use it unless I have to. Too much like perl or
ruby.

Here is #do:

> zz:={1,2,3}
> xx:=0
> zz do: [:yy | xx:=xx+yy]


> zz do: [:yy | xx:=xx+yy]


error: an instance of Number does not respond to "do:"


Ken Ferry

unread,
Sep 5, 2009, 3:34:56 PM9/5/09
to f-sc...@googlegroups.com
..but regardless of why you have a -do: and I don't, printString returns a string.  It doesn't send the string to a console anywhere, so pure iteration is not useful here.  Try -[System log:].  

> sys log:'hi'

-Ken

Ken Ferry

unread,
Sep 5, 2009, 3:39:04 PM9/5/09
to f-sc...@googlegroups.com
Er, try -[System log:] if you're hoping that the result ends up in the system log, in Console.app.  

If you want something to show up in the F-Script interpreter window, which I confusingly referred to as the console above, then you return it.

-Ken

WyattBiker

unread,
Sep 5, 2009, 4:07:03 PM9/5/09
to F-Script
I cant imagine a smalltalk with a #do: message. try this

xx:=0. {1,2,3} do: [:yy | xx:=xx+yy]. xx.

Hopefully you will see a 6.


The log works and so also printString outputs to the workspace
correctly. It's the iteration that doesnt print.

On Sep 5, 3:28 pm, Ken Ferry <kenfe...@gmail.com> wrote:

Ken Ferry

unread,
Sep 5, 2009, 4:35:23 PM9/5/09
to f-sc...@googlegroups.com
On Sat, Sep 5, 2009 at 1:07 PM, WyattBiker <wyatt...@gmail.com> wrote:

I cant imagine a smalltalk with a #do: message. try this

xx:=0. {1,2,3} do: [:yy | xx:=xx+yy]. xx.

Hopefully you will see a 6.

It was added in version 2.0 which was just released, and indeed I did not have it installed properly.

F-Script didn't have it previously because message patterns suffice.

The log works and so also printString outputs to the workspace
correctly. It's the iteration that doesnt print.

-printString just returns a string.  It prints to memory.

I recommended `sys log:` above, but I see in the F-Script 2.0 release notes that this is now deprecated.  The relnotes have this to say:

Three globals, stdin, stdout and stderr, give access to the standard IO streams. stdout and stderr provide a method for outputing a string: -(void) print:(NSString *)string. For example:

stdout print:'hello world'

You should use it instead of the log: method provided by the sys object, as the sys object is not available when developing F-Script classes.

-Ken

Ken Ferry

unread,
Sep 5, 2009, 4:39:59 PM9/5/09
to f-sc...@googlegroups.com
On Sat, Sep 5, 2009 at 1:35 PM, Ken Ferry <kenf...@gmail.com> wrote:
On Sat, Sep 5, 2009 at 1:07 PM, WyattBiker <wyatt...@gmail.com> wrote:

I cant imagine a smalltalk with a #do: message. try this

xx:=0. {1,2,3} do: [:yy | xx:=xx+yy]. xx.

Incidentally, idiomatic F-Script for this would be 

{1,2,3} \#+

Philippe Mougin

unread,
Sep 5, 2009, 5:33:41 PM9/5/09
to F-Script


On Sep 5, 10:07 pm, WyattBiker <wyattbi...@gmail.com> wrote:
> I cant imagine a smalltalk with a #do: message. try this
>
> xx:=0. {1,2,3} do: [:yy | xx:=xx+yy]. xx.
>
> Hopefully you will see a 6.
>
> The log works and so also printString outputs to the workspace
> correctly. It's the iteration that doesnt print.

As Ken noted, the printString method does not print. It just returns a
printable description of the receiver (that we call its "print string"
in Smalltalk). You then see it printed in the F-Script shell because
of the read-eval-print loop you are in. Just like when you type "3 +
4" and see "7" printed in the shell. The do: method, on the other
hand, does not return anything; this is why there is nothing printed
in the shell.
-Philippe

WyattBiker

unread,
Sep 5, 2009, 6:16:15 PM9/5/09
to F-Script
Thanks :) Here is my chance to make a Transcript window.

By the wat I am looking at the source code for FSTranscript class and
it seems to be doing nothing. Is it for future?

Philippe Mougin

unread,
Sep 5, 2009, 6:45:36 PM9/5/09
to F-Script
Yes, FSTranscript might be used in the future to provide a transcript
object like in other Smalltalks. However, using the stdout object and
the standard Mac OS X console application we already have some
equivalent to the Transcript. I don't know if an F-Script specific
transcript would be worth it. Thinking more about this is on my to-do
list 8-)
Contributions to that reflexion are welcome, of course.

Philippe

WyattBiker

unread,
Sep 6, 2009, 10:33:52 AM9/6/09
to F-Script
Here are my reasons why you need it:

1) The Console logging is slow and mixed in with many other messages.
There is an annoying delay before you output appears.

2) One of the beauties of Smalltalk and it's workspaces is to test and
debug quick snippets. With a transcript window or pane you see your
output instantly.

3) Many new user's have never used Smalltalk and may want to play
around with the more complex messages and see the output. It all
starts with people playing around and learning in a command window.

4) I am thinking that this is a trivial but important addition. At
least the way I see it is to have an in memory transcript buffer that
is written to. Then a toggle button on your browser window displays
the buffer in a scrollable window. Just one global Transcript
singleton object should suffice and some simple methods. E.g. cr.
datetime: YES/NO.

5) Is there anyway to fix the NSString stringWithFormat: or a
workaround? I don't understand the issue with variable argument lists
but maybe special cases should be made to pass them as arrays.

Thanks

Philippe Mougin

unread,
Sep 7, 2009, 9:40:56 AM9/7/09
to F-Script
Yes, the case for a transcript object seems very strong. I think there
will be one in the future.

Regarding support for format strings: one could implement it, by
creating a method that takes an array of objects instead of a variable
argument list and then doing the formating job. However, this is not
the approach we take with F-Script (or Smalltalk in general). As Ken
explained, just let the objects describe themselves and assemble the
fragments using the ++ method (string concatenation). Additionaly,
using reduction can make expressions even nicer. This approach is
simple and works well. Give it a try!
Philippe
Reply all
Reply to author
Forward
0 new messages