[1/3] from: louisaturk::eudoramail::com at: 2-Apr-2002 13:43
Hi rebols, I wrote this function to add spaces in the right places to line up columns of text: pad: func [form-length val] [loop form-length - length? to-string val [prin ]] It works fine except that it also prints ?unset? How do I get rid of the ?unset? ? Louis
[2/3] from: louisaturk:eudoramail at: 2-Apr-2002 15:08
Hi again everyone, Never mind. I figured it out. I was calling the function as follows: print ["123" pad 10 "123"]. pad must be separated from print in order to work properly. Louis At 01:43 PM 4/2/2002 -0600, you wrote:
[3/3] from: ingo:2b1 at: 3-Apr-2002 10:58
Hi Louis, your problem is, that you _print_ from within a 'print statement, and that doesn't work (as you've figured yourself by now).
>> print ["123" pad 10 "456"]
123 ?unset? What happened here is, that 'print first found a value ("123") and then a function, so, to be able to know what to print, 'print _first_ executed the 'pad function. 'Pad used 10 and "456" as it's parameters and printed seven spaces. Then it returned the last value. Given that 'prin was the last part of 'pad, and that 'prin doesn't return a value, the value returned by 'pad was unset, too. Now 'print was ready to do its job: print the value "123", a space, and the value returned by 'pad, which was unset. Now, you have to change your function to either print everything: pad1: func [ form-length val ] [ loop form-length - length? to-string val [prin " "] prin val ]
>> prin "123" pad1 10 "456" print ""
123 456 or to just return the padded value: pad2: func [ form-length val /local ret ] [ ret: make string! 20 loop form-length - length? to-string val [insert ret " "] append ret val ]
>> print ["123" pad2 10 "456"]
123 456 I hope that shed a little light on the mistery ... Ingo Am Die, 2002-04-02 um 21.43 schrieb Dr. Louis A. Turk: