Thank you Joh-Tob...I'll have a good look at that because ultimately I do
want to use picolisp objects.
I just came back to say that changing the argument name from *L (also the
global symbol) to Larg seemed to crack this. It's as if...given a conflict
between a global symbol and a local argument symbol, inside a function, the
local argument symbol wins which seems fair enough. I tried this as a
result of Alex's remark that L will go back to whatever it was before the
function. I suppose I'm used to passing variables in through the prototype
by reference :)

(setq *L '(a))

(de doit (Larg)
   (prog
      (setq *L (append Larg '(b)))
      (prinl "inside of fn *L is " *L) ) )

(doit *L)
(prinl "outside fn *L is " *L)

#inside of fn *L is ab
#outside fn *L is ab



On 17 December 2016 at 22:51, Joh-Tob Schäg <johtob...@gmail.com> wrote:

> For the case:
> (setq A ( 1 2 3 ))
> There is no (efficient) way to find the symbol (1 2 3) is bound to. So
> would you have to know the symbol all the time.
>
> (de add-to-global-list (Sym Value)
>    (setq Sym (cons Value Sym)))
> (de delete-from-global-list (Sym)
>    (setq Sym (cdr Sym)))
>
> But i guess you do not want to pass the symbol around. But the function
> still does need to what global symbol to work on. You can either use
> Picolisp object system for that or you can implement it on your own.
>
> (de return-list-handler (@Symbol)
>    (fill '((Op-code . Operands)
>       (cond
> ((= Op-code "add") (setq @Symbol (cons (car Operands) @Symbol)))
> ((= Op-code "sort") (setq @Symbol (sort @Symbol)))
> ((= Op-code "readcar") (car @Symbol))
> ((= Op-code "readcdr") (cdr @Symbol))
> ((= Op-code "del") (setq @Symbol (cdr @Symbol)))))))
>
> You use it like that:
> (setq c (return-list-handler '*Global-List))
> (c "add" 1)
> (c "add" 2)
> (c "add" 3)
> (c "add" 4)
> *Global-List #-> (4 3 2 1)
> (c "sort")
> (c "readcar") #-> 1
>
> I would really recommend you using objects though even though they are
> basically the same under the hood.
> Does that answer our question?
>
>
> 2016-12-17 22:01 GMT+01:00 Alexander Burger <a...@software-lab.de>:
>
>> Hi Dean,
>>
>> On Sat, Dec 17, 2016 at 06:02:29PM +0000, dean wrote:
>> > #{Is it possible to change a list AND keep it's name the same at
>> different
>> > program levels}#
>> > (setq L '(a))
>> > (de doit_temp (L) (prog (setq L (append L '(b))) (prinl "inside of fn L
>> is
>> > " L))  )
>> > (de doit_perm (L) (setq NewL (append L '(b))))
>> > (doit_temp L)
>> > (prinl "outside of fn L is " L)
>> > (doit_perm L)
>> > (prinl "outside of fn NewL is " NewL)
>> >
>> > #inside of fn L is ab
>> > #outside of fn L is a
>> > #outside of fn NewL is ab
>>
>> Hmm, again I can't really understand what your question is. And you seem
>> to use
>> the wrong terminology.
>>
>> The key concept is "symbol binding". Let me try to clear some things up:
>>
>>
>> > #{Is it possible to change a list AND keep it's name the same at
>> different
>> > program levels}#
>>
>> A list does not have a "name". You can only *bind* a symbol to a list.
>>
>> Binding is fundamental concept of Lisp, and you should *really* try to
>> understand it thoroughly before writing any programs. Please study the
>> example
>> code in the distro and at rosettacode.org!
>>
>>
>> > (setq L '(a))
>>
>> This binds the symbol 'L' globally to the list '(a)'.
>>
>>
>>
>> > (de doit_temp (L)
>> >    (prog
>> >       (setq L (append L '(b)))
>> >       (prinl "inside of fn L is " L) ) )
>>
>> (The 'prog' is not needed)
>>
>> The symbol 'L' is bound to some value when the function is called. Then
>> it is
>> extended by appending '(b)' to whatever value that is. That is printed,
>> then 'L'
>> is restored upon function return to whatever global value it had before.
>>
>>
>> > (de doit_perm (L)
>> >    (setq NewL (append L '(b))) )
>>
>> 'NewL' is global from this function.
>>
>> It should be named *NewL according to the PicoLisp naming conventions.
>>
>>
>>
>> All this explains the output you get :)
>>
>> - Alex
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>

Reply via email to