## "place" in the function "inc"

Pondering the philosophy behind the language
lyl
Posts: 44
Joined: Sun Mar 25, 2018 5:00 am

### "place" in the function "inc"

The meaning of "place" in the syntax: (inc place [num]) is:
either a symbol or a place in a list structure holding a number, or a number returned by an expression.(from the newlisp manuel)

I still don't quite understand the real meaning of "place", as in the following code coming from 《Code Patterns in newLISP》:

Code: Select all

``````;; sum accumulator
(define (sum (x 0)) (inc 0 x))

(sum 1)    → 1
(sum 2)    → 3
(sum 100)  → 103
(sum)      → 103

sum  → (lambda ((x 0)) (inc 103 x))``````
In this example, what is the "place, and why"?

fdb
Posts: 64
Joined: Sat Nov 09, 2013 8:49 pm

### Re: "place" in the function "inc"

It refers to a place in a list, so you can do:

Code: Select all

``````> (set 'places '(0 0 0))
(0 0 0)
> (inc (places 1))
1
> places
(0 1 0)
>
``````

The example from Code Patterns illustrates that a function is also a list (a lambda list) and you can also update that list with inc.

lyl
Posts: 44
Joined: Sun Mar 25, 2018 5:00 am

### Re: "place" in the function "inc"

Many thanks.
Still, how is the lambda list updated in my example? Or, which element of the lambda list is changed by inc?

fdb
Posts: 64
Joined: Sat Nov 09, 2013 8:49 pm

### Re: "place" in the function "inc"

In your example the 0 after inc in the lambda list is changed by inc.

Your lambda list says :(define (sum (x 0)) (inc 0 x))

after you do (sum 1) your lambda list is :
(define (sum (x 0)) (inc 1 x)), so the 0 has become a 1.

after you do another (sum 1) your lambda list is :
(define (sum (x 0)) (inc 2 x)), so the 1 has become a 2.