Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Mapping series

 [1/5] from: massung:gmai:l at: 8-Mar-2006 13:56


So, I'm sure REBOL has some sort of support for this, but I have yet to find it. Does REBOL have any built-in support for traditional mapping functions that are found in Lisp? For example, I'd like to do something similar to: square: func [n] [ 2 * n ] map :square [ 1 2 3 4 ] == [ 1 4 9 16 ] map :uppercase [ "jeff" "massung" ] == [ "JEFF" "MASSUNG" ] I can, of course, roll my own MAP function easily enough, but I thought I'd see if there was a native function to do this (under a different name that isn't obvious to me) first. If there isn't, I think this would be a very valuable addition to the language, BTW. Jeff M. -- massung-gmail.com

 [2/5] from: greggirwin:mindspring at: 8-Mar-2006 13:22


Hi Jeff, JM> So, I'm sure REBOL has some sort of support for this, but I have yet to find JM> it. Does REBOL have any built-in support for traditional mapping functions JM> that are found in Lisp? Oddly enough, there isn't a native one. It has come up a number of times, and many folks have written their own; I don't know why RT hasn't included one yet. It's possible they're still looking for the right design. e.g. with refinements and such, I think there's more to it than just do the same thing Lisp does, when creating a standard function. Here's one, written by Larry Palmiter, that I use sometimes: map: apply: func [fn blk args /local result][ result: copy [] repeat el blk [append/only result fn :el args] result ] -- Gregg

 [3/5] from: massung:gma:il at: 8-Mar-2006 14:37


Thanks, I'll take a closer look at that one when I get a moment. Along the same lines, has anyone come up with a version of "gensym" that can be used? For example, using VID, I may want to dynamically create controls that access themselves. I currently don't know of a way to do this without generating a symbol to use. Here's a brief example of what I mean: dyn-btn: does [ join [] [ gensym: 'button "foo" [ gensym/text: "bar" ] ] Obviously, however, I can't use "gensym:" over and over again, I need to have a way of "creating" the symbol on the fly and accessing it. I suppose I could use to-word and coerce a generated string for the name (like Lisp does). But is there a "nicer" way to do this? On 3/8/06, Gregg Irwin <greggirwin-mindspring.com> wrote:
> Hi Jeff, > JM> So, I'm sure REBOL has some sort of support for this, but I have yet
<<quoted lines omitted: 18>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- massung-gmail.com

 [4/5] from: greggirwin:mindspring at: 8-Mar-2006 13:47


Hi Jeff, JM> Thanks, I'll take a closer look at that one when I get a moment. Along the JM> same lines, has anyone come up with a version of "gensym" that can be used? JM> For example, using VID, I may want to dynamically create controls that JM> access themselves. I currently don't know of a way to do this without JM> generating a symbol to use. Here's a brief example of what I mean: gensym: func [/with 'word /reset /local count] [ count: [0] count/1: add 1 either reset [0] [count/1] to word! join any [word 'g] count/1 ] Now, if you're talking about actions in faces, that's easy, because you can just use face/<facet> in the action block. i.e. FACE in the action block refers to the face that the action is attached to. dyn-btn: does [ join [] ['button "foo" [face/text: "bar"]] ] view layout dyn-btn BTW, the above function shows the "persistent" quality of series values in functions. In this case, it's leveraged so an enclosing object isn't needed; sometimes it can bite you though, so you want to use COPY most of the time when declaring local series in functions. -- Gregg

 [5/5] from: volker::nitsch::gmail::com at: 8-Mar-2006 22:40


On 3/8/06, Jeff Massung <massung-gmail.com> wrote:
> Thanks, I'll take a closer look at that one when I get a moment. Along the > same lines, has anyone come up with a version of "gensym" that can be used? > > For example, using VID, I may want to dynamically create controls that > access themselves.
if they want to access themself, they are objects, they know who they are. Means they have a 'self. Except if you use action-blocks in vid, these are closures, staying bound to their original environment. They get the appropriate face as parameter 'face.
> I currently don't know of a way to do this without > generating a symbol to use. Here's a brief example of what I mean: > > dyn-btn: does [ > join [] [ gensym: 'button "foo" [ gensym/text: "bar" ] > ] > > Obviously, however, I can't use "gensym:" over and over again,
Not?! Looking confused for context. Maybe not elegant example, but still possible :) The basic trick with making a context and getting a word from it is universal. dyn-btn: func[foo /local ctx] [ ctx: context[ sym: none lay: compose copy/deep [ sym: button (foo) [ probe sym/text probe lay ] ] ] ] buttons: copy[] lay: copy[] repeat i 10[ append buttons ctx: dyn-btn join "btn" i append lay ctx/lay ] ? lay lay: layout lay foreach btn buttons[ probe btn/sym/text ] view lay
> I need to > have a way of "creating" the symbol on the fly and accessing it. I suppose I
<<quoted lines omitted: 38>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted