Steve,
Yes, I thought of this too and discussed it with Slava. My use case
was:
ERROR: no-foo key ;
: lookup-foo ( key assoc -- value )
at* [ no-foo ] unless ;
You really want the bad key included in the error tuple, and like you
said, it's tough to do this currently.
Like if* and if-empty for null and empty sequences respectively, you
could define an if-at combinator that has the desired behavior.
[ no-foo ] unless-at
The disadvantage of doing this is you have to define three new if
combinators: if-at, when-at, unless-at, and the code is slightly
harder to read because you have to read all the way to the end to see
what it's doing. If at* were as you suggest, you could just use at*
with if, when, and unless -- no need for new combinators.
So, yes, at* has the wrong stack effect right now, and I hope to
change it eventually.
Doug
On Jan 31, 2009, at 10:50 AM, Steve Weeks wrote:
> Wouldn't it be better if at* was:
>
> : at* ( key assoc -- key/value ? ) ... ;
>
> If the key exists then the stack is "value t" otherwise the stack is
> "key f". That way you could code something like:
>
> key at* [ <do something with the key> ] unless ... ;
>
> Right now it returns "f f", the redundant f's aren't that useful and
> you have to code:
>
> key dup at [ <do something with the value> ] [ <do something with the
> key> ] if ... ;
>
> Usually I'm building the object if the key doesn't exist so it would
> nice if the code was:
>
> key at* [ <new-object> ] unless ;
>
> Or am I completely missing the idom?
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk