Greeting and Challenge!

View: New views
18 Messages — Rating Filter:   Alert me  

Greeting and Challenge!

by Paulo Köch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello! =)

My name is Paulo Köch. I'm from Porto, Portugal. I discovered Io through _why's post and I'm
enjoying it very much!

I already tried to contribute, putting two issues up on Io's website. Is that the best place to
submit them? I also sent a path for the TextMate bundle to Rob. I hope to hear from him
soon.

And, for the challenge!!! =P How can you implement a function that outputs the name of the
receiver? For example, calling 'obj receiverName' would return "obj". I tried to explore "call
message"'s capabilities but didn't find anything appropriate (previous was the closest thing).

I ran into this problem when I was trying to implement a generic "printf style debug" helper,
somewhat like var_dump in PHP (this was before using slotSummary). Since Io is King on
reflection, i wanted to output the callee's name. Any tips on better debugging solutions will
also be greatly appreciated! =)

Thanks for the wonderful language!
Paulo Köch



Re: Greeting and Challenge!

by Danya Alexeyevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

IMHO, the best way to submit bugs is either to this list or directly
to Steve Dekorte.

You can write: pDebug := method(call message prev name print; self)

I don't understand exactly what you mean about debugging. Is something
like: {{{ object println method }}} not enough?

Cheers,
- Danya

Re: Greeting and Challenge!

by Jeremy Tregunna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Unfortunately there is no easy way to to get the previous message. You  
can go through all the message objects returned by Collector  
allObjects, check for the next message attached to the message you're  
at's unqiueId that's the same as your message (call message)... for  
instance:

Message previous := method(
     Collector allObjects foreach(o,
         if(o isKindOf(Message),
             if(o next uniqueId == self uniqueId, return o)
         )
     )
)

But that's highly inefficient as it traverses all objects in the  
heap... but it's better than nothing. Unfortunately, since Io is an  
eager language (don't take the fact it lets you delay evaluation as  
being lazy, all messages are evaluated as messages at the very least,  
all the time)... it's very difficult to implement a "previous" pointer  
on the AST when the AST allows you to make manipulations to it. It  
would have to be special, and I'm all for that, but it's a tough sell  
to many.

--
Jeremy Tregunna
jtregunna@...



On 6-May-08, at 10:06 AM, Paulo Köch wrote:

> Hello! =)
>
> My name is Paulo Köch. I'm from Porto, Portugal. I discovered Io  
> through _why's post and I'm
> enjoying it very much!
>
> I already tried to contribute, putting two issues up on Io's  
> website. Is that the best place to
> submit them? I also sent a path for the TextMate bundle to Rob. I  
> hope to hear from him
> soon.
>
> And, for the challenge!!! =P How can you implement a function that  
> outputs the name of the
> receiver? For example, calling 'obj receiverName' would return  
> "obj". I tried to explore "call
> message"'s capabilities but didn't find anything appropriate  
> (previous was the closest thing).
>
> I ran into this problem when I was trying to implement a generic  
> "printf style debug" helper,
> somewhat like var_dump in PHP (this was before using slotSummary).  
> Since Io is King on
> reflection, i wanted to output the callee's name. Any tips on better  
> debugging solutions will
> also be greatly appreciated! =)
>
> Thanks for the wonderful language!
> Paulo Köch
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>


Re: Greeting and Challenge!

by Danya Alexeyevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>  You can write: pDebug := method(call message prev name print; self)
Oops. A while ago it seemed to me that message tree does have previous
pointer...

Since it's not there, you're left with inspecting the 'self' object
for it's type and slots, but not for the name it was referenced
under...

- Danya

Re: Greeting and Challenge!

by Danya Alexeyevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Very funny! The slot 'previous' is implemented in internal
representation, accessor method for it is implemented too and it is
even documented -- but not bound into Message namespace!

Steve, please fix this :)

On Tue, May 6, 2008 at 10:16 PM, Danya Alexeyevsky <me.dendik@...> wrote:

> >  You can write: pDebug := method(call message prev name print; self)
>  Oops. A while ago it seemed to me that message tree does have previous
>  pointer...
>
>  Since it's not there, you're left with inspecting the 'self' object
>  for it's type and slots, but not for the name it was referenced
>  under...
>
>  - Danya
>

Re: Greeting and Challenge!

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2008-05-06, at 7:06 AM, Paulo Köch wrote:
> And, for the challenge!!! =P How can you implement a function that  
> outputs the name of the
> receiver? For example, calling 'obj receiverName' would return "obj".


There's no Message previous method, which AFACT, is what you're asking  
for. One trick to get around it that's reasonably efficient would be  
to do this (which only works when called within a block/method:

Message messageBefore := method(m,
        if(next == m, return self)
        if(next, return next messageBefore(m))
        nil
)

Object receiverName := method(
        call sender call activated message messageBefore(call message) name
)


test := method(
        foo := Object clone
        foo receiverName println
)

test

Re: Greeting and Challenge!

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2008-05-06, at 11:20 AM, Danya Alexeyevsky wrote:
> Very funny! The slot 'previous' is implemented in internal
> representation, accessor method for it is implemented too and it is
> even documented -- but not bound into Message namespace!

It was ifdef'd out - I've pushed a version with it enabled and it  
seems to work but this is experimental.

Cheers,
- Steve


Re: Greeting and Challenge!

by Paulo Köch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello!

On Tue, May 6, 2008 at 7:06 PM, Danya Alexeyevsky <me.dendik@...> wrote:
> IMHO, the best way to submit bugs is either to this list or directly
>  to Steve Dekorte.

Why do we have the issues section in the page, then? Shouldn't it just
point here? It confuses people (as it confused me! =P).

>  I don't understand exactly what you mean about debugging. Is something
>  like: {{{ object println method }}} not enough?
Debugging printf style is just printing all values (from most to least
suspicious) to find a bug.
I didn't quite understand that snippet of code. =/

On Wed, May 7, 2008 at 2:00 AM, Steve Dekorte <steve@...> wrote:
>  It was ifdef'd out - I've pushed a version with it enabled and it
>  seems to work but this is experimental.
 Why was it def'ed out? Any particular reason?

Steve, just to make things clear, what you did was just iterate all
the method tokens until we found the one before our target, right?

Cheers!

Re: Greeting and Challenge!

by Danya Alexeyevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>  > I don't understand exactly what you mean about debugging. Is something
>  > like: {{{ object println method }}} not enough?
>  Debugging printf style is just printing all values (from most to least
>  suspicious) to find a bug.
>  I didn't quite understand that snippet of code. =/

The {{{ println }}} method prints some representation of object the
message is sent to and returns the object unmodified. So, you can
insert it seamlessly anywhere within your code to see what data is
passed there. So, the code {{{ object method }}} differs from {{{
object println method }}} only in object's value being printed to
standard output. That's the simplest of all printf-style debug
approaches in Io (and among other languages, probably, too).

----------
There are also very flexible debug hooks built into language that
require some wrapper code to create a useable debuggers. I use it for
some very basic profiling my code. Try inserting this snippet
somewhere in the beginning of your code:

{{{
Debugger vmWillSendMessage := method(
        if(self message label beginsWithSeq("io/"), return) # filter
some messages
        write(self message label, ":")
        write(self message lineNumber, ":")
        write(self message asString asMutable escape slice(0, 60), "\n")
)
Coroutine currentCoroutine setMessageDebugging(true)
}}}

Cheers,
- Danya

Re: Greeting and Challenge!

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2008-05-07, at 7:17 AM, Paulo Köch wrote:

> Steve, just to make things clear, what you did was just iterate all
> the method tokens until we found the one before our target, right?

I iterated the message objects in the method, yes.

Re: Greeting and Challenge!

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2008-05-07, at 11:43 AM, Steve Dekorte wrote:

>
> On 2008-05-07, at 7:17 AM, Paulo Köch wrote:
>
>> Steve, just to make things clear, what you did was just iterate all
>> the method tokens until we found the one before our target, right?
>
> I iterated the message objects in the method, yes.

BTW, here's how to implement it using the latest Io with Message  
previous support:

receiverName := method(call message previous name)


Re: Greeting and Challenge!

by Paulo Köch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, May 7, 2008 at 3:26 PM, Danya Alexeyevsky <me.dendik@...> wrote:
>  The {{{ println }}} method prints some representation of object the
>  message is sent to and returns the object unmodified. So, you can
>  insert it seamlessly anywhere within your code to see what data is
>  passed there. So, the code {{{ object method }}} differs from {{{
>  object println method }}} only in object's value being printed to
>  standard output. That's the simplest of all printf-style debug
>  approaches in Io (and among other languages, probably, too).

Yes, I got that. What struck me as odd was it being written as {{{
object println method }}} instead of {{{ object method println}}}.
I guess it's just personal preference (and the fact that most other
languages don't return self in println =P).

>  There are also very flexible debug hooks built into language that
>  require some wrapper code to create a useable debuggers. I use it for
>  some very basic profiling my code. Try inserting this snippet
>  somewhere in the beginning of your code:
>
>  {{{
>  <snip>
>  }}}

I've just read about it in the docs. At first glance, it was somehow
not clear how to use the hook (as in, what to call in the method for
it to be useful), but you example is a wonderful starting point. Maybe
it should be the default method, since it's only called when the flag
is on (the default impl. seems too bare). Just an opinion. =)

On Wed, May 7, 2008 at 8:43 PM, Steve Dekorte <steve@...> wrote:
>  BTW, here's how to implement it using the latest Io with Message
>  previous support:
>
>  receiverName := method(call message previous name)

Yes, it becomes very simple with previous. =)

Re: Greeting and Challenge!

by Danya Alexeyevsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>  Yes, I got that. What struck me as odd was it being written as {{{
>  object println method }}} instead of {{{ object method println}}}.
>  I guess it's just personal preference (and the fact that most other
>  languages don't return self in println =P).

I wanted to show that you can inspect intermediate results besides
finite results of expressions. I should've explained it. (There is an
unspoken rule in mathematics to give first non-trivial case as
example. {{{ object method println }}} would feel almost the same as
{{{ object println }}}, which does not work well as an example of
approach to debugging).

>  I've just read about it in the docs. At first glance, it was somehow
>  not clear how to use the hook (as in, what to call in the method for
>  it to be useful), but you example is a wonderful starting point. Maybe
>  it should be the default method, since it's only called when the flag
>  is on (the default impl. seems too bare). Just an opinion. =)

Thanks :) I think, it's up to Steve to decide: there actually is
already a little more primitive example in the Debugger object (either
{{{ Debugger getSlot("vmWillSendMessage") }}} or look at
libs/iovm/io/Debugger.io) and I built my version by expanding that
one.

There are also a few people on the list that are willing to write a
full-featured debugger... But I think it won't happen soon.

Cheers,
- Danya

Re: Greeting and Challenge!

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2008-05-07, at 2:57 PM, Danya Alexeyevsky wrote:

> There are also a few people on the list that are willing to write a
> full-featured debugger... But I think it won't happen soon.

I'd be willing to set aside some time to help with this if we can get  
someone willing to get it talking to TextMate so we can step through  
code and have it highlighted in the editor.

strange error message

by Friedrich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

List do (
  filter := method(selFun, result,
    if (self size == 0,
      result reverse
      ,
      if ((selFun call (self first)),
        (self last (self size -1)) filter (selFun, result prepend(self first))
        ,
        (self last (self size -1)) filter(selFun, result)
))))
       
   
   
   

numbers := list (1,-1,2,-5,"jacob","friedrich")
numbers println
filtered := numbers filter(block(x, x>=0), list())
filtered println

output:
io filter.io
list(1, -1, 2, -5, "jacob", "friedrich")

  Exception: argument 0 to method '>=' must be a Sequence, not a 'Number'
  ---------
  >=                                  filter.io 18
  Object call                          filter.io 6
  List filter                          filter.io 9

Not very useful IMHO

Regards
Friedrich

Re: strange error message

by Tyler McMullen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure if you were asking for an explanation of the error message or
just stating its badness.  If it was the former, what's going on is you're
trying to compare a string to a number.  If you pop into the REPL and try:

"foo" >= 12

You'll get the same error.  One work around you might consider is reversing
the arguments.  "x >= 0" does not work... but "0 < x" should (or does for
that matter).


Tyler McMullen

On Wed, May 21, 2008 at 1:09 AM, Friedrich Dominicus <
frido@...> wrote:

>   List do (
> filter := method(selFun, result,
> if (self size == 0,
> result reverse
> ,
> if ((selFun call (self first)),
> (self last (self size -1)) filter (selFun, result prepend(self first))
> ,
> (self last (self size -1)) filter(selFun, result)
> ))))
>
>
>
>
>
> numbers := list (1,-1,2,-5,"jacob","friedrich")
> numbers println
> filtered := numbers filter(block(x, x>=0), list())
> filtered println
>
> output:
> io filter.io
> list(1, -1, 2, -5, "jacob", "friedrich")
>
> Exception: argument 0 to method '>=' must be a Sequence, not a 'Number'
> ---------
> >= filter.io 18
> Object call filter.io 6
> List filter filter.io 9
>
> Not very useful IMHO
>
> Regards
> Friedrich
>  
>

Re: strange error message

by Friedrich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Tyler McMullen" <tbmcmullen@...> writes:

> I'm not sure if you were asking for an explanation of the error message or just stating its badness.  If it was the
> former, what's going on is you're trying to compare a string to a number.  If you pop into the REPL and try:
> "foo" >= 12
> You'll get the same error.  One work around you might consider is reversing the arguments.  "x >= 0" does not
> work... but "0 < x" should (or does for that matter).
> Tyler McMullen
I think this is a bad error message. And following your arguments,
it's even worse. That meanss that 0 <= x != x >= 0, I think this is
ridicoulus

Regards
Friedrich

--
Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim
Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus

Re: strange error message

by David Nolen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The problem is that you are reading 0 <= x and 0 >= x as a  
mathematical statement.  It is not.  For example, in Python this is  
possible:

def z():pass
0 < z < "A string"
=> True

A pretty absurd hierarchy designed to preserve 0 < x && x > 0 while  
adding little to the language itself.

0 <= x in Io means pass the message <= with the argument x to the  
Number instance 0.
x >= 0 in Io means pass the message >= with the argument 0 to the  
unknown instance x (in your example, possibly a Number instance,  
possibly a Sequence instance).

In your code, a Sequence instance received a >= message with an  
argument it did not expect, a Number instance, and threw an Exception.

You're seeing the mathematical comparison operators as operators, not  
as what they really are in Io; they are simply a syntactical  
convenience mapped to methods.

Frustrating at first perhaps, but it also means the Io is startlingly  
uniform once you get used to it.

David

On May 22, 2008, at 1:19 AM, Friedrich Dominicus wrote:

> "Tyler McMullen" <tbmcmullen@...> writes:
>
> > I'm not sure if you were asking for an explanation of the error  
> message or just stating its badness.  If it was the
> > former, what's going on is you're trying to compare a string to a  
> number.  If you pop into the REPL and try:
> > "foo" >= 12
> > You'll get the same error.  One work around you might consider is  
> reversing the arguments.  "x >= 0" does not
> > work... but "0 < x" should (or does for that matter).
> > Tyler McMullen
> I think this is a bad error message. And following your arguments,
> it's even worse. That meanss that 0 <= x != x >= 0, I think this is
> ridicoulus
>
> Regards
> Friedrich
>
> --
> Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim
> Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
>
>

LightInTheBox - Buy quality products at wholesale price