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

Combining a word and a value in one argument

 [1/8] from: tim::johnsons-web::com at: 26-Sep-2000 18:12


Howdy: It would be great if I could have a function that would take a rebol word as an argument and print out both the word and it's value: i.e: test-int: 4 tst test-int
>>test-int: 4
This would be similar to a c function using the preprocessor stringizer as in #define PRINT(x) print(x,#x) print(int x,char* x_name) { return printf("%s: %d",x_name,x); } test-int = 4 PRINT(test-int); // gives test-int: 4 I tried playing with first system/words but couldn't come up with anything consistant. TIA -Tim

 [2/8] from: tim:johnsons-web at: 26-Sep-2000 19:00


I'm sending this again. I sent this earlier with another email. It arrived, this didn't, so am trying again....... ;====================== Howdy: It would be great if I could have a function that would take a rebol word as an argument and print out both the word and it's value: i.e: test-int: 4 tst test-int
>>test-int: 4
This would be similar to a c function using the preprocessor stringizer as in #define PRINT(x) print(x,#x) print(int x,char* x_name) { return printf("%s: %d",x_name,x); } test-int = 4 PRINT(test-int); // gives test-int: 4 I tried playing with first system/words but couldn't come up with anything consistant. TIA -Tim

 [3/8] from: al:bri:xtra at: 27-Sep-2000 15:07


Tim wrote:
> It would be great if I could have a function that would take a rebol word
as an argument and print out both the word and it's value:
>> help source
USAGE: SOURCE 'word DESCRIPTION: Prints the source code for a word. SOURCE is a function value. ARGUMENTS: word -- (Type: word)
>> source test-int
test-int: 4 If you need a version of 'source that can be written to a file, let me know, and I put it on the list. I hope that helps! Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/

 [4/8] from: jsc:dataheaven at: 27-Sep-2000 5:25


Why not simply: tst: func [w [word!]] [ print rejoin [w ": " get w] ]
>> var: 4
== 4
>> tst 'var
var: 4 On Wed, 27 Sep 2000, you wrote:

 [5/8] from: jkinraid:clear at: 27-Sep-2000 15:24


Hi Tim,
> It would be great if I could have a function that > would take a rebol word as an argument and
<<quoted lines omitted: 17>>
> -Tim >> test-int: 4
== 4
>> ?? test-int
test-int: 4 == 4
>> source ??
??: func [ {Prints a variable name followed by its molded value. (for debugging)} 'name ][ print either word? :name [rejoin [name ": " mold name: get name]] [mold :name] :name ] The trick is that you use a lit-word! as an argument for a function. That way, the argument isn't evaluated.
>> tst: func ['one two] [print [one two]] >> a: 1
== 1
>> b: 2
== 2
>> tst a b
a 2 So you use the 'get function to find out what the value is.
>> tst: func ['one two] [print [get one two]] >> a: 1
== 1
>> tst a b
1 2 But that will fail if you don't pass a word! as an argument.
>> tst 1 2
** Script Error: get expected word argument of type: any-word. ** Where: get one two So all that is needed is some code to check if the argument is a word or not.
>> tst: func ['one two] [print [either word? :one [get one] [one] two]] >> tst a b
1 2
>> tst 3 4
3 4 The rest of the code in the ?? function just deals with molding the value. Have fun, Julian Kinraid

 [6/8] from: tim:johnsons-web at: 26-Sep-2000 20:01


Hi All: Yes!! That is great! I can handle that little tick. The other two responses were very enlightening too. This is what I was trying to make work, I just needed to use 'get. Great list, I wish there were more like this.... now what do you know about dosemu? Just kidding. :) Thanks Tim [jsc--dataheaven--de] wrote:

 [7/8] from: sharriff:aina:med-iq at: 27-Sep-2000 7:39


Hi Tim try this out, haveŽnt tested it though, first thing that came to my mind.... test-func: func [ arg [word!] ] [ print 'arg "this is the lit-word value" print arg "this is the word! value" ] Sharriff Aina med.iq information & quality in healthcare AG Gutenbergstr. 42 41564 Kaarst tel.: 02131-3669-0 fax: 02131-3669-599 www.med-iq.de

 [8/8] from: joel:neely:fedex at: 27-Sep-2000 8:05


Hi, Tim... [tim--johnsons-web--com] wrote:
> Great list, I wish there were more like this.... > now what do you know about dosemu? >
Based on the following, from http://www.dict.org/ ... From WordNet (r) 1.6 : emu n 1: any of various systems of units for measuring electricity and magnetism [syn: electromagnetic unit] 2: large Australian flightless bird similar to the ostrich but smaller [syn: Dromaius novaehollandiae, Emu novaehollandiae] ... I'd guess that dosemu is either a random consumer of electricity, or a large Australian flightless bird that also doesn't run too well. ;-) -jn-

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