How do I write contents of variable to a text file?
Newbie question here...
I'd like to write the output of the "what" function to a text file.
So here is what I have done:
I've created a variable called "text" and assigned the output of "what" to it
Now I want to write the content of the "text" variable to a txt file...
Any help is appreciated. Thanks in advance!
posted by: Hugo 7-Nov-2014/13:29:39-8:00
Your use of the word 'variable' worries me here, since this might be at the crux of why you're struggling with this.
You didn't assign the output of the function 'what to the word 'text. You may think you did, but you didn't. :) All you did was store a word, in this case a word which references a function, in a block (which is also referenced to a word, text).
So I'm not sure if you want the output (result) of a function, or the source of the function itself written to a file? If it's the latter, perhaps something like:
what: does ["hello"]
write %contents.txt remold [to-set-word t/1 get to-get-word t/1]
If you want to write the output of the function to a file, try:
write %contents.txt do t/1
or, if you want to store a value that can be read or loaded:
write %contents.txt mold do t/1
posted by: Edoc 7-Nov-2014/17:35:49-8:00
Hi Hugo, if you want to write the output of the "what" function to a text file then in R3 type:
posted by: Linh 8-Nov-2014/1:09:05-8:00
Linh's answer works because the 'what function *doesn't return* the listing of words. It just prints them on screen. The 'echo function can be used to capture that screen activity.
posted by: Nick 8-Nov-2014/7:52:26-8:00
You can see the source of any function:
You can also access an editable string containing that source:
That allows you to create a new function containing an edited version of the source. Try this:
what2: do replace mold :what "foreach [word args]" "return total"
posted by: Nick 8-Nov-2014/8:23:57-8:00
Thanks a lot for the help guys. I really appreciated!
posted by: Hugo 10-Nov-2014/17:57:14-8:00