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

Create words dynamically

 [1/7] from: tmoeller:fastmail:fm at: 5-Mar-2006 19:30


Hi, it seemed i have lost some knowledge over the time. How can i create words dynamically from the content of a block and use these words for filling them up with new content like this: words: [ "phhtmcl" "phhocml" ] content: [ "phhtmcl/111" "phhocml/222" "phhtmcl/333" "phhocml/444"] i now want to create two words like phhtmcl: [] and phhocml: [] with an foreachloop over the words-series. These words should be filled with with an other foreach loop on the content-block, where the first part is the indicator in which word the content should stored an the second one ist the content itself. how can i use these created words in the following scriptparts? i played around a bit with to-set-word etc on the console but failed to get it right. has anybody done this before or has good tutorial for this. Thorsten -- http://www.fastmail.fm - Faster than the air-speed velocity of an unladen european swallow

 [2/7] from: massung:g:mail at: 5-Mar-2006 12:35


I'm pretty new to REBOL (and loving it so far), but couldn't you just coerce the strings to words using TO-WORD? foreach symbol in words [ w: to-word symbol ; do something with w ] Or perhaps I'm missing something? Jeff M. On 3/5/06, Thorsten Moeller <tmoeller-fastmail.fm> wrote:
> Hi, > it seemed i have lost some knowledge over the time.
<<quoted lines omitted: 21>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- massung-gmail.com

 [3/7] from: greggirwin:mindspring at: 5-Mar-2006 13:22


Hi Thorsten, TM> How can i create words dynamically from the content of a block and use TM> these words for filling them up with new content like this: TM> words: [ "phhtmcl" "phhocml" ] TM> content: [ "phhtmcl/111" "phhocml/222" "phhtmcl/333" "phhocml/444"] ... TM> These words should be filled with with an other foreach loop on the TM> content-block, where the first part is the indicator in which word the TM> content should stored an the second one ist the content itself. how can TM> i use these created words in the following scriptparts? Something like this?
>> words: [ "phhtmcl" "phhocml" ]
== ["phhtmcl" "phhocml"]
>> content: [ "phhtmcl/111" "phhocml/222" "phhtmcl/333" "phhocml/444"]
== ["phhtmcl/111" "phhocml/222" "phhtmcl/333" "phhocml/444"]
>> foreach word words [set to word! word copy []]
== []
>> foreach cmd content [word-val: parse cmd "/" append get to word! first word-val load seco
nd word-val] == [222 444]
>> phhtmcl
== [111 333] The long line that parses the command and loads the data will no doubt need some tuning, and would benefit from being broken apart, but you get the idea. Now, what I have to ask is: What is the real goal and use? I know if often seems easy to expose REBOL, load files and just DO them. If that's the case, then why the string formats? If the goal is for users to create files that make the app more dynamic, why not use a dialect? -- Gregg

 [4/7] from: greggirwin::mindspring::com at: 5-Mar-2006 13:29


Hi Jeff, Welcome to REBOL! JM> I'm pretty new to REBOL (and loving it so far), but couldn't you just coerce JM> the strings to words using TO-WORD? JM> foreach symbol in words [ JM> w: to-word symbol JM> ; do something with w JM> ]
>> words: [ "phhtmcl" "phhocml" ]
== ["phhtmcl" "phhocml"]
>> foreach symbol words [w: to-word symbol]
== phhocml What we've done here is set the value of the word W to reference a word! value created from the symbol, but not created new words from those symbols.
>> w
== phhocml
>> phhocml
** Script Error: phhocml has no value ** Near: phhocml Given a word, it's easy to use SET to set it to an initial value. This will create global words the way I think you expected.
>> foreach symbol words [set to-word symbol none]
== none
>> phhocml
== none Words, binding, series, and evaluation behavior aren't always obvious, especially if you're coming from other languages, so don't be afraid to ask questions if things don't work as expected. Happy REBOLing! -- Gregg

 [5/7] from: massung::gmail::com at: 5-Mar-2006 16:03


Very much like Lisp bindings. While I program in C/C++ professionally, I have an good Lisp and Forth background, so I'm finding REBOL very refreshing. Very much like taking my two favorite languages and mooshing them into one. :-) Thanks for the reply and explanation. Jeff M. -- massung-gmail.com On 3/5/06, Gregg Irwin <greggirwin-mindspring.com> wrote:

 [6/7] from: greggirwin:mindspring at: 5-Mar-2006 15:43


Hi Jeff, JM> Very much like Lisp bindings. While I program in C/C++ professionally, I JM> have an good Lisp and Forth background, so I'm finding REBOL very JM> refreshing. You should be very comfortable with REBOL. One of the big things to remember is that *everything* in REBOL is data, and it's when data is evaluated that things happen. JM> Very much like taking my two favorite languages and mooshing JM> them into one. :-) Just wait until you get into PARSE and View! :) -- Gregg

 [7/7] from: tmoeller::fastmail::fm at: 6-Mar-2006 16:16


Hi Gregg, thanks, it works very well for my needs. I remembered to use something like set and get but not exactly enough to get it to work. Thorsten On Sun, 5 Mar 2006 13:22:37 -0700, "Gregg Irwin" <greggirwin-mindspring.com> said:
> Hi Thorsten, > TM> How can i create words dynamically from the content of a block and
<<quoted lines omitted: 32>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- http://www.fastmail.fm - A fast, anti-spam email service.

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