List or quoted List

Q&A's, tips, howto's
Post Reply
ssqq
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

List or quoted List

Post by ssqq »

function map accept a quoted list as its seconds arguments:

(map inc '(1 2 3 4 5))

but above expression returned a list? or a quoted list? I think its should be a quoted list, because it could used with second map:

(map inc (map inc '(1 2 3 4)))

I don't know if it is a macro with map, but the expression with map is evaluted with some delay.

How to know a primitive function is macro or common function?

The evaluted order about primitive function? I know `eval` is first should be evaluate than `println`.

cormullion
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: List or quoted List

Post by cormullion »

(map inc '(1 2 3 4 5))
but above expression returned a list? or a quoted list?
It returns an unevaluated list:

Code: Select all

(2 3 4 5)
As does:

Code: Select all

'(1 2 3 4)
(1 2 3 4)
which is why you can do:

Code: Select all

(map inc (map inc '(1 2 3 4))
;-> (3 4 5 6)
I don't think built-in functions are exactly macros, but many of them have special behaviour: e.g. if fortunately does not evaluate all the expressions passed to it. If it did, programming would be very difficult...

ssqq
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: List or quoted List

Post by ssqq »

I think must have a type of data structure -> 'lazy-list' in newLISP, which would not be evaluted when passed into function as argument. most of list processing function would return a 'lazy-list'.

Post Reply