beneroth changed the topic of #picolisp to: PicoLisp language | The scalpel of software development | Channel Log: https://libera.irclog.whitequark.org/picolisp | Check www.picolisp.com for more information
chexum has quit [Ping timeout: 260 seconds]
chexum has joined #picolisp
f[x] has joined #picolisp
f[x] has quit [Remote host closed the connection]
rob_w has joined #picolisp
fuxoft has joined #picolisp
<fuxoft> Hello everyone.
<fuxoft> I have problems understanding the example in the docs for (pop).
<fuxoft> The usage is supposed to be (pop 'var), according to the docs.
<fuxoft> So how can you even to (pop S) (without apostrophe) and why does it return a and not (a b c)?
<abu[7]> Hi fuxoft
<fuxoft> *even DO
<abu[7]> 'pop' evaluates its arg (the normal way)
<abu[7]> The result must be a 'var'
<abu[7]> ie. a cell or a sym
<abu[7]> (setq L (1 2 3) S 'L) (pop S)
<abu[7]> -> 1
<fuxoft> Is there an explanation what exaclty 'var' is? I thought it has to be a symbol
<abu[7]> It is in @doc/ref.html
<abu[7]> Function Reference
<abu[7]> Other (derived) data types
<fuxoft> I see "var - Variable: Either a symbol or a cons pair"
<abu[7]> right
<fuxoft> But no explanation what does it mean when it's a cons pair.
<fuxoft> If var is a cons pair, then itc CAR is taken?
<abu[7]> For example:
<abu[7]> (setq L '((1 2 3) (4 5 6))) (pop L)
<abu[7]> -> 1
<abu[7]> L is now ((2 3) (4 5 6))
<fuxoft> That's exactly what I don't understand.
<abu[7]> So the cell in L is popped
<abu[7]> L has 2 cells
<fuxoft> It seems to me that (pop) does two completely unrelated things
<fuxoft> L has 2 cells, the first one is popped and it should be (1 2 3), not 1...?
<abu[7]> If you do pop "by hand":
<fuxoft> This is probably something fundamental I am unable to understand from the docs
<abu[7]> (setq L '((1 2 3) (4 5 6))) (prog1 (caar L) (set L (cdar L)))
<abu[7]> 'set' also operates on a 'var'
<fuxoft> What setq does is that the value of symbol L is now the list ((123)(456)), ok?
<abu[7]> T
<fuxoft> What (pop 'L) does is that it returns the CAR of this list and removes it, ok?
<abu[7]> Not remove
<abu[7]> set to its CDR
<abu[7]> (prog1 (caar L) (set L (cdar L)))
<abu[7]> How about this?
<abu[7]> ap: (setq L '((1 2 3)))
<abu[7]> -> ((1 2 3))
<abu[7]> ap: (set L 7)
<abu[7]> -> 7
<abu[7]> ap: L
<abu[7]> -> (7)
<abu[7]> Or:
<fuxoft> ?? I am completely baffled by this.
<abu[7]> ap: (setq L '((1 2 3)))
<abu[7]> -> ((1 2 3))
<abu[7]> ap: (cdar L)
<abu[7]> -> (2 3)
<abu[7]> ap: (set L (cdar L))
<abu[7]> -> (2 3)
<abu[7]> ap: L
<abu[7]> -> ((2 3))
<abu[7]> Perhaps draw it in box-notation?
<fuxoft> I think I understand what the value of Symbol is. I have no idea what "value of list" means
<abu[7]> Hm
<abu[7]> Do you see this:
<fuxoft> You are doing (set '((1 2 3)) something.... ) ?
<abu[7]> ap: (setq L (1 2 3))
<abu[7]> -> (1 2 3)
<abu[7]> ap: (set (cdr L) "abc")
<abu[7]> -> "abc"
<abu[7]> ap: L
<abu[7]> -> (1 "abc" 3)
<abu[7]>
<abu[7]> (cdr L) is the *second* cell
<abu[7]> it is 'set'
<fuxoft> (cdr (1 2 3)) should be (2 3), not 2 ...?
<abu[7]> 2 is the CADR
<abu[7]> cdr gives the second cell
<abu[7]> (2 . (3 4))
<abu[7]> oops
<abu[7]> (2 . (3))
<fuxoft> Yes.
<abu[7]> or (2 . (3 . NIL))
<fuxoft> OK
<abu[7]> So (set (cdr L) replaces the '2'
<fuxoft> That's what I don't get. SHouldn't it replace the whoe (2 . (3)) ?
<fuxoft> *whole
<fuxoft> I have also read this article several times and still don't understand it :( https://picolisp-explored.com/picolisp-explored-the-set-function
<abu[7]> No, the cell is (2 . (3))
<abu[7]> a var
<abu[7]> so the CAR is set
<fuxoft> So if (set) is used with a symbol, it has completely different functionality than when it's used with a list?
<abu[7]> No, the same
<abu[7]> a sym or a cell are both a pointer
<abu[7]> set puts a value there
<fuxoft> The "pointer" of (1 2 3) is (2 3)?
<fuxoft> I don't understand that "cell is a pointer".
<fuxoft> I understand that (1 2 3) is represented as value 1 and a pointer to (2 3).
<abu[7]> Right
<fuxoft> If I replace that pointer with "abc", I should be getting (1 . "abc"), but I am getting (1 "abc" 3).
<abu[7]> In @doc/structures under "Pair" and "Symbol"
<abu[7]> you ses the "pointers"
<abu[7]> 'set', 'pop', 'inc' and others simply take this pointer
<abu[7]> Pair
<abu[7]> |
<abu[7]> V
<abu[7]> +-----+-----+
<abu[7]> | CAR | CDR |
<abu[7]> +-----+-----+
<abu[7]> Symbol
<abu[7]> |
<abu[7]> V
<abu[7]> +-----+-----+
<abu[7]> | | | VAL |
<abu[7]> +--+--+-----+
<fuxoft> Do you mean this section? https://software-lab.de/doc/ref.html#cell
<abu[7]> No, doc/structures
<abu[7]> : (vi "@doc/structures")
<abu[7]> T
<fuxoft> Here, the "VAL" is referenced only for Symbol, not for Pair.
<abu[7]> Just a name
<abu[7]> set does not care
<abu[7]> It accesses where it is pointed to
<abu[7]> a VAL or a CAR
<abu[7]> The VAL of a symbol happens to be the CAR of that cell, but this is not relevant on the Lisp level
<abu[7]> What counts is that a 'var' is a place where you can store something
<abu[7]> and retrieve it
<abu[7]> (setq L '(a b c d))
<abu[7]> +-----+-----+ +-----+-----+ +-----+-----+ +-----+-----+
<abu[7]> | a | ---+---->| b | ---+---->| c | ---+---->| d | / |
<abu[7]> |
<abu[7]> ^
<abu[7]> +-----+-----+ +-----+-----+ +-----+-----+ +-----+-----+
<abu[7]> L ---+
<abu[7]> (set (cdr L) ..
<abu[7]> replacej 'b'
<abu[7]> Hmm, not readable in IRC ☺
<abu[7]> We should make a PilCon again
fuxoft has quit [Ping timeout: 256 seconds]
<abu[7]> Perhaps 'view' is better to communicate in IRC:
<abu[7]> : (setq L '(a (b . c) d))
<abu[7]> -> (a (b . c) d)
<abu[7]> : (view L)
<abu[7]> +-- a
<abu[7]> |
<abu[7]> +---+-- b
<abu[7]> | |
<abu[7]> | c
<abu[7]> |
<abu[7]> +-- d
<abu[7]> -> NIL
<abu[7]> -> xyz
<abu[7]> : (set (cdr L) 'xyz)
<abu[7]> : (view L)
<abu[7]> Throttled :(
<abu[7]> Shorter bits:
<abu[7]> : (setq L '(a (b . c) d))
<abu[7]> -> (a (b . c) d)
<abu[7]> : (view L)
<abu[7]> +-- a
<abu[7]> |
<abu[7]> | |
<abu[7]> +---+-- b
<abu[7]> | c
<abu[7]> |
<abu[7]> +-- d
<abu[7]>
<abu[7]> : (set (cdr L) 'xyz)
<abu[7]> -> xyz
<abu[7]> : (view L)
<abu[7]> +-- xyz
<abu[7]> +-- a
<abu[7]> |
<abu[7]> |
<abu[7]> +-- d
<abu[7]>
<abu[7]>
<abu[7]> : (setq L '(a (b . c) d))
<abu[7]> -> (a (b . c) d)
<abu[7]> : (set (cadr L) 'xyz)
<abu[7]> -> xyz
<abu[7]> +-- a
<abu[7]> | |
<abu[7]> |
<abu[7]> : (view L)
<abu[7]> +---+-- xyz
<abu[7]> | c
<abu[7]> |
<abu[7]> +-- d
<abu[7]> Still ugly :(
rob_w has quit [Remote host closed the connection]
fuxoft has joined #picolisp
<fuxoft> Huh, now I see that some of my replies probably didn't go through because I don't see them in the chat archive. Thank you very much, I will try reading through all that again.
fuxoft has quit [Client Quit]
<abu[7]> Strange
<abu[7]> Anyway ask whenever you are back. I try to explain better :)
rob_w has joined #picolisp
beneroth has quit [Ping timeout: 276 seconds]
beneroth has joined #picolisp
corecheckno has quit [Remote host closed the connection]
fuxoft has joined #picolisp
<fuxoft> I am back. :)
<fuxoft> Let me know if I understand this correctly (hopefully).
<fuxoft> * "var" can be a symbol or a pair
<abu[7]> Right :)
<fuxoft> * If var a is symbol, the function (e.g. "(pop)") operates on its value
<abu[7]> Yes
<fuxoft> * if var is a pair, the function operates on its CAR
<abu[7]> Exactly
<fuxoft> * The implementation remains the same in both cases because PicoLisp just works with the raw pointer to the structure, WITHOUT ZEROING THE BOTTOM 4 BITS. That means the pointer points to Value in the case of Symbol and to CAR in the case of Pair
<abu[7]> Perfect!
<fuxoft> Great. So to understand how the hell this works, it helps to have fairly good understanding of the low level cell structure. :)
<abu[7]> Yes, it is the core of undersianding the machinery
<abu[7]> That's why I said some
<abu[7]> times
<abu[7]> that doc/structures *is* picolisp
<abu[7]> The rest is just examples
<fuxoft> The more I understand it the more I am amazed at the low-level elegance of PicoLisp. Pity I didn't know about it 20 years ago when my brain worked better...
<abu[7]> ☺
fuxoft has quit [Quit: Client closed]
gahr has quit [Quit: leaving]
gahr has joined #picolisp
aw- has quit [Ping timeout: 244 seconds]
aw- has joined #picolisp
rob_w has quit [Read error: Connection reset by peer]
lagash has quit [Remote host closed the connection]
lagash has joined #picolisp
aw- has quit [Quit: Leaving.]
aw- has joined #picolisp