Need Clarification

A

anil mannava

Guest
Hi can you tell me the difference b/w the programs.
1.) a=300:400 b=400:500 c=list(a b)
2.) a=300:400 b=400:500 c='(a b)

Thanks Regards,
Anil Mannava
 
Hi Anil,

Anil Mannava <anilmannavaforyou@gmail.com> writes:
Hi can you tell me the difference b/w the programs.

1.) a=300:400 b=400:500 c=list(a b)
2.) a=300:400 b=400:500 c='(a b)
Yes. Point 1. is easy; focusing on the right side of the assignment,

list(a b)

is a normal function call. Each argument is to be evaluated, and the
results—the values of the `a` and `b` variables—applied to the `list`
function, which builds a *fresh* list of its arguments. The result is
thus:

((300:400) (400:500))

Number 2. is a bit more complicated to understand. The first thing to
remember is that:

'(a b)

is just a syntax shortcut for:

(quote (a b))

This is very important, because `quote` is NOT a normal function. It is
a special operator which admits a single argument, and returns it
*unevaluated*. In this case, the single argument to quote is:

(a b)

which, by the rules of the SKILL/SKILL++ program text parser (the
*reader*), is a list of two symbols, `a` and `b`. The result is thus
simply:

(a b)

Note that that list is built once, *by the reader*, and never touched
again. Each evaluation of `quote` will return that same list object.
This is very different from e.g.:

list('a 'b)

which, while it produces a very similar result, allocates a fresh list
on each call; that difference is crucial if the list if to be modified
afterwards!


Hope this helps,
Damien Diederen

--
http://crosstwine.com
tel: +49 89 2189 2939
cell: +49 174 3489 428
 
On Wednesday, January 23, 2013 2:28:47 PM UTC+5:30, Damien Diederen wrote:
Hi Anil, Anil Mannava <anilmannavaforyou@gmail.com> writes: > Hi can you tell me the difference b/w the programs. > > 1.) a=300:400 b=400:500 c=list(a b) > 2.) a=300:400 b=400:500 c='(a b) Yes. Point 1. is easy; focusing on the right side of the assignment, list(a b) is a normal function call. Each argument is to be evaluated, and the results—the values of the `a` and `b` variables—applied to the `list` function, which builds a *fresh* list of its arguments. The result is thus: ((300:400) (400:500)) Number 2. is a bit more complicated to understand. The first thing to remember is that: '(a b) is just a syntax shortcut for: (quote (a b)) This is very important, because `quote` is NOT a normal function. It is a special operator which admits a single argument, and returns it *unevaluated*. In this case, the single argument to quote is: (a b) which, by the rules of the SKILL/SKILL++ program text parser (the *reader*), is a list of two symbols, `a` and `b`. The result is thus simply: (a b) Note that that list is built once, *by the reader*, and never touched again. Each evaluation of `quote` will return that same list object. This is very different from e.g.: list('a 'b) which, while it produces a very similar result, allocates a fresh list on each call; that difference is crucial if the list if to be modified afterwards! Hope this helps, Damien Diederen -- http://crosstwine.com tel: +49 89 2189 2939 cell: +49 174 3489 428
Hi Damien,
Thank you for the clarification. it is very helpful.

Regards,
Anil Mannava
 

Welcome to EDABoard.com

Sponsor

Back
Top