From: David R. Sky
Subject: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411220236560.6069@viper.wapvi.bc.ca>
I've been learning XLisp via Nyquist, and  have been stuck on lists
in the following way:

The user defines 16 pairs of variables (numerically), and I've put
them in a list:

(setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))

and using a looping function, trying to get the numeric values
passed to a and b for a defun:

(dotimes (i count)
(setf a (nth (* i 2) mylist))
(setf b (nth (+ 1 (* i 2)) mylist)))

What is 'passed' to a and b is not the numeric value, but the
alphanumeric values a1 b1 etc.

I've been googling extensively and looking in Nyquist, XLisp and
Lisp manuals, to no avail. I have a hunch it's something simple -
what is it please?

Thanks :)

David

-- 

From: Pascal Bourguignon
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <87brdqqgzf.fsf@thalassa.informatimago.com>
"David R. Sky" <···@viper.wapvi.bc.ca> writes:

> I've been learning XLisp via Nyquist, and  have been stuck on lists
> in the following way:
> 
> The user defines 16 pairs of variables (numerically), and I've put
> them in a list:
> 
> (setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))
> 
> and using a looping function, trying to get the numeric values
> passed to a and b for a defun:
> 
> (dotimes (i count)
> (setf a (nth (* i 2) mylist))
> (setf b (nth (+ 1 (* i 2)) mylist)))
> 
> What is 'passed' to a and b is not the numeric value, but the
> alphanumeric values a1 b1 etc.
> 
> I've been googling extensively and looking in Nyquist, XLisp and
> Lisp manuals, to no avail. I have a hunch it's something simple -
> what is it please?

if a1, ... b16 are _variables_ you should build the list as:

    (setf mylist (list a1 b1 a2 b2 a3 b3 ... a16 b16))

instead of using a literal list of _symbols_ (not alphanumeric values!).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
From: David R. Sky
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411220421450.8770@viper.wapvi.bc.ca>
Excellent, thank-you very much Pascal! I've seen that code form previously 
but didn't understand it could be used that way. David



On Mon, 22 Nov 2004, Pascal Bourguignon wrote:

> "David R. Sky" <···@viper.wapvi.bc.ca> writes:
>
>> I've been learning XLisp via Nyquist, and  have been stuck on lists
>> in the following way:
>>
>> The user defines 16 pairs of variables (numerically), and I've put
>> them in a list:
>>
>> (setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))
>>
>> and using a looping function, trying to get the numeric values
>> passed to a and b for a defun:
>>
>> (dotimes (i count)
>> (setf a (nth (* i 2) mylist))
>> (setf b (nth (+ 1 (* i 2)) mylist)))
>>
>> What is 'passed' to a and b is not the numeric value, but the
>> alphanumeric values a1 b1 etc.
>>
>> I've been googling extensively and looking in Nyquist, XLisp and
>> Lisp manuals, to no avail. I have a hunch it's something simple -
>> what is it please?
>
> if a1, ... b16 are _variables_ you should build the list as:
>
>    (setf mylist (list a1 b1 a2 b2 a3 b3 ... a16 b16))
>
> instead of using a literal list of _symbols_ (not alphanumeric values!).
>
>

-- 
From: Thomas A. Russ
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <ymioehp7qv5.fsf@sevak.isi.edu>
"David R. Sky" <···@viper.wapvi.bc.ca> writes:

> 
> Excellent, thank-you very much Pascal! I've seen that code form previously 
> but didn't understand it could be used that way. David

At this point, I would suggest you take another look at the issues of
evaulation and quoting of arguments in Lisp.  It is a pretty
fundamental issue and one that you will need to grasp in order to
succeed in Lisp programming.

> >> (setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))
> >    (setf mylist (list a1 b1 a2 b2 a3 b3 ... a16 b16))
> >
> > instead of using a literal list of _symbols_ (not alphanumeric values!).


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: David R. Sky
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411230028430.15963@viper.wapvi.bc.ca>
It's the first time I've constructed such a list and then tried to use it. 
And yes I do understand that a single character can mean a heck of a big 
difference in the results! I understand from using the format command what 
comes out the result end. And also of course whether what I've written works 
or not! :)

David


On Mon, 22 Nov 2004, Thomas A. Russ wrote:

> "David R. Sky" <···@viper.wapvi.bc.ca> writes:
>
>>
>> Excellent, thank-you very much Pascal! I've seen that code form previously
>> but didn't understand it could be used that way. David
>
> At this point, I would suggest you take another look at the issues of
> evaulation and quoting of arguments in Lisp.  It is a pretty
> fundamental issue and one that you will need to grasp in order to
> succeed in Lisp programming.
>
>>>> (setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))
>>>    (setf mylist (list a1 b1 a2 b2 a3 b3 ... a16 b16))
>>>
>>> instead of using a literal list of _symbols_ (not alphanumeric values!).
>
>
>

-- 
From: Pascal Bourguignon
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <878y8solfe.fsf@thalassa.informatimago.com>
"David R. Sky" <···@viper.wapvi.bc.ca> writes:
> >>>> (setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))
> >>>    (setf mylist (list a1 b1 a2 b2 a3 b3 ... a16 b16))
> >>>
> >>> instead of using a literal list of _symbols_ (not alphanumeric values!).
> > [...]
> > At this point, I would suggest you take another look at the issues of
> > evaulation and quoting of arguments in Lisp.  It is a pretty
> > fundamental issue and one that you will need to grasp in order to
> > succeed in Lisp programming.
>
> It's the first time I've constructed such a list and then tried to use
> it. And yes I do understand that a single character can mean a heck of
> a big difference in the results! I understand from using the format
> command what comes out the result end. And also of course whether what
> I've written works or not! :)

Yes, but the question is whether you understand now what happens when
you evaluate:
                '(a1 b1)

and what happens when you evalute:

                (list a1 b1)

?


It would be useless for you to just remember the two forms and try one
or the other at random until you get the result you want...

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
From: David R. Sky
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411240234250.1984@viper.wapvi.bc.ca>
On Tue, 23 Nov 2004, Pascal Bourguignon wrote:

> Yes, but the question is whether you understand now what happens when
> you evaluate:
>                '(a1 b1)
>
> and what happens when you evalute:
>
>                (list a1 b1)
>
Okay. As I understand it,

(setf mylist '(apple boat cat))

is a literal list of apple, boat and cat, whereas

(setf mylist (list apple boat cat))

would be a list of the values _assigned_ to the variable names apple, 
boat and cat.

Is that the correct way of looking at these two list forms?

Thanks, David
From: Chris Capel
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <10q8q1l5v1cbp44@corp.supernews.com>
David R. Sky wrote:
> Okay. As I understand it,
> 
> (setf mylist '(apple boat cat))
> 
> is a literal list of apple, boat and cat, whereas
> 
> (setf mylist (list apple boat cat))
> 
> would be a list of the values _assigned_ to the variable names apple,
> boat and cat.
> 
> Is that the correct way of looking at these two list forms?

I believe it is. I'd make sure, though, that you understand what happens
when you write

(setf mylist '(list apple boat cat))

In this case, mylist => (list apple boat cat), because you have a quote,
which prevents anything inside of it from being evaluated.

In fact, I think the crux here is the different between reading code and
evaluating it, and how you can control what where, and in what order the
various phases take place. For instance, can you see something wrong with
this code?

(defparameter *x* '(apples oranges bananas))

(defun get-normal-fruits (&optional extra-fruits)
  (dolist (f extra-fruits)
    (push f *x*)
  *x*)

>  (get-normal-fruits '(kiwis))
=> '(apples oranges bananas kiwis)

Chris Capel
From: David R. Sky
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411240528480.7287@viper.wapvi.bc.ca>
Chris,

You wrote: I'd make sure, though, that you understand what happens
when you write

(setf mylist '(list apple boat cat))

In this case, mylist => (list apple boat cat), because you have a
quote, which prevents anything inside of it from being evaluated.

David: Thanks, that makes more sense now. So the quote prevents
_any_ kind of evaluating in the list.

Chris: can you see something wrong with this code?

(defparameter *x* '(apples oranges bananas))

(defun get-normal-fruits (&optional extra-fruits) 
(dolist (f extra-fruits)     (push f *x*)   *x*)

>  (get-normal-fruits '(kiwis)) 
=> '(apples oranges bananas kiwis)

David: No, I don't know what f and push mean or do, not yet. And I
assume defparameter means something like defining parameter(s)?
I've been learning Nyquist (working with audio; based on XLisp)
rather haphazardly, I haven't been formally following an online
guide so far (which I would need because I'm using a screen
reader). Is there a simple online guide I can begin following? My
background is BASIC (long long ago) and WorPerfect 5.1 macro
language programming, both imperative languages as I understand it.

Thanks

David

-- 
From: Pascal Bourguignon
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <87k6sbl294.fsf@thalassa.informatimago.com>
"David R. Sky" <···@viper.wapvi.bc.ca> writes:
> David: No, I don't know what f and push mean or do, not yet. And I
> assume defparameter means something like defining parameter(s)?
> I've been learning Nyquist (working with audio; based on XLisp)
> rather haphazardly, I haven't been formally following an online
> guide so far (which I would need because I'm using a screen
> reader). Is there a simple online guide I can begin following? My
> background is BASIC (long long ago) and WorPerfect 5.1 macro
> language programming, both imperative languages as I understand it.


> (defparameter *x* '(apples oranges bananas))

It's basically (setf *x* '(apples oranges bananas)) but in
Common-Lisp, when the variable *x* does not exist yet, SETF/SETQ/SET
are not specified to do anything useful. DEFPARAMETER or DEFVAR have
to be used, and DEFPARAMETER is better because DEFVAR does not change
the value of an already existing variable while DEFPARAMETER does.

> (defun get-normal-fruits (&optional extra-fruits) (dolist (f
> extra-fruits)     (push f *x*)   *x*)


(DOLIST (variable list) body)

executes body with variable bound to each element of list in turn.

dolist exists in Xlisp.
http://www-2.cs.cmu.edu/~rbd/doc/nyquist/part12.html#81


f is the name of the variable that takes as value each element of the
list extra-fruits in turn.
 

(PUSH x l) === (setf l (cons x l))

You can add Common-Lisp functions or macro that are missing in XLisp.
For example:

    (defmacro push (value list) `(setf ,list (cons ,value ,list)))


(this is not entirely correct since it would give surprizing results for:

    (defparameter stack-vec #((list a b) (list c d) (list e f)))
    (defparameter i 0)
    (push :val (aref stack-vec (incf i)))

but XLisp has no defsetf, no get-setf-expansion, and no incf either...
(that's why it's better to use Common-Lisp than any other lisp, they
always lack something important or useful)).



In Common-Lisp, there's a couple of music/audio packages too:
http://www.cliki.net/admin/search?words=music

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
From: Pascal Bourguignon
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <87act7mkpm.fsf@thalassa.informatimago.com>
Chris Capel <······@iba.nktech.net> writes:

> David R. Sky wrote:
> > Okay. As I understand it,
> > 
> > (setf mylist '(apple boat cat))
> > 
> > is a literal list of apple, boat and cat, whereas
> > 
> > (setf mylist (list apple boat cat))
> > 
> > would be a list of the values _assigned_ to the variable names apple,
> > boat and cat.
> > 
> > Is that the correct way of looking at these two list forms?

Yes. '(apple boat cat) is read as: (quote (apple boat cat))

SETF is a macro or special operator that does not evaluate its first
argument MYLIST (but it analyzes it) and that evaluates its second
argument.

QUOTE is a special operator that returns its argument unevaluated and
unchanged: (apple boat cat)

Now SETF assigns this value (apple boat cat) to the variable denoted by MYLIST.
(this value may be exactly the same one found in the "source" of the program.


In the second case, LIST is a function that builds a new list
containing its arguments.  (Therefore, this new list is a _copy_ of
the argument list).


Compare:

(let ((*print-circle* t) 
      (exp '(setf mylist #1='(apple boat cat))) 
      (srclist #1#))
  (eval exp) 
  (print (list srclist mylist)))

prints:

    (#1=(APPLE BOAT CAT) #1#) 

while:

(let ((apple '(iBook 12\" G3))
      (boat "North Wind 58 Ketch") 
      (cat "Passe-Muraille"))
  (declare (special apple boat cat))
  (let ((*print-circle* t)
        (exp '(setf mylist #1=(list apple boat cat)))
        (valist #1#))
    (eval exp)
    (print (list valist mylist))))

prints:

    ((#1=(IBOOK |12"| G3) #2="North Wind 58 Ketch" #3="Passe-Muraille")
     (#1# #2# #3#)) 


> (defparameter *x* '(apples oranges bananas))
> 
> (defun get-normal-fruits (&optional extra-fruits)
>   (dolist (f extra-fruits)
>     (push f *x*)

You missed this:  )

>   *x*)
> 
> >  (get-normal-fruits '(kiwis))
> => '(apples oranges bananas kiwis)

The actual result is: 

    '(kiwis apples oranges bananas)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
From: David Sletten
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <fA3pd.60753$hN1.40035@twister.socal.rr.com>
Pascal Bourguignon wrote:


> 
>>(defparameter *x* '(apples oranges bananas))
>>
>>(defun get-normal-fruits (&optional extra-fruits)
>>  (dolist (f extra-fruits)
>>    (push f *x*)
> 
> 
> You missed this:  )
> 
> 
>>  *x*)
>>
>>
>>> (get-normal-fruits '(kiwis))
>>
>>=> '(apples oranges bananas kiwis)
> 
> 
> The actual result is: 
> 
>     '(kiwis apples oranges bananas)
> 

You guys are confusing poor Mr. Sky. The actual result is:
(get-normal-fruits '(kiwis)) => (KIWIS APPLES ORANGES BANANAS) ;No quote...


David Sletten
From: David R. Sky
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411241556520.28305@viper.wapvi.bc.ca>
On Wed, 24 Nov 2004, David Sletten wrote:

>You guys are confusing poor Mr. Sky. The actual result is:
> (get-normal-fruits '(kiwis)) => (KIWIS APPLES ORANGES BANANAS) ;No quote...
>
*chuckling* I've been lost and confused for a while! But I'll get it 
eventually!

David Sky
From: Pascal Bourguignon
Subject: Re: Probably a simple question about list variables
Date: 
Message-ID: <87brdnktky.fsf@thalassa.informatimago.com>
David Sletten <·····@slytobias.com> writes:

> Pascal Bourguignon wrote:
> >>> (get-normal-fruits '(kiwis))
> >>
> >>=> '(apples oranges bananas kiwis)
> > The actual result is:     '(kiwis apples oranges bananas)
> >
> 
> You guys are confusing poor Mr. Sky. The actual result is:
> (get-normal-fruits '(kiwis)) => (KIWIS APPLES ORANGES BANANAS) ;No quote...

Oops, right.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
From: David R. Sky
Subject: Pascal: Re: Probably a simple question about list variables
Date: 
Message-ID: <Pine.LNX.4.61.0411221451310.29975@viper.wapvi.bc.ca>
Pascal,

I finished the audio plug-in I was working on, but cannot find a valid 
e-address, can you send that to me offlist. Thanks David



On Mon, 22 Nov 2004, Pascal Bourguignon wrote:

> "David R. Sky" <···@viper.wapvi.bc.ca> writes:
>
>> I've been learning XLisp via Nyquist, and  have been stuck on lists
>> in the following way:
>>
>> The user defines 16 pairs of variables (numerically), and I've put
>> them in a list:
>>
>> (setf mylist '(a1 b1 a2 b2 a3 b3 ... a16 b16))
>>
>> and using a looping function, trying to get the numeric values
>> passed to a and b for a defun:
>>
>> (dotimes (i count)
>> (setf a (nth (* i 2) mylist))
>> (setf b (nth (+ 1 (* i 2)) mylist)))
>>
>> What is 'passed' to a and b is not the numeric value, but the
>> alphanumeric values a1 b1 etc.
>>
>> I've been googling extensively and looking in Nyquist, XLisp and
>> Lisp manuals, to no avail. I have a hunch it's something simple -
>> what is it please?
>
> if a1, ... b16 are _variables_ you should build the list as:
>
>    (setf mylist (list a1 b1 a2 b2 a3 b3 ... a16 b16))
>
> instead of using a literal list of _symbols_ (not alphanumeric values!).
>
>

--