Append! in the diagram?

I am studying the R5RS circuit at the moment (from PocketScheme), and I found that I can use the function built into some variants of the circuit, but not all: Append!

In other words, a destructive list change.

I'm not so interested in the actual code as an answer, as an understanding of the process by which you can pass a list as a function (or a vector or a string), and then mutate it.

example:

(define (append! lst var)
    (cons (lst var))
)

When I use this approach as stated above, I need to do something like (define list (append! foo (bar))that which I would like to get more general.

+3
source share
2 answers

, , . PLT , set-car! set-cdr! ( "" set-mcar! set-mcdr!). append! SRFI-1. append! . SRFI , cons .

append!, , , , , , . :

(define (my-append! a b)
  (if (null? (cdr a))
      (set-cdr! a b)
      (my-append! (cdr a) b)))

, , , 1 a () ( ), b. a 1, set-cdr! .

, , , . , a, cons, (<last element> . null). , , a , null cdr. , set-cdr!, , , . , my-append! cdr of a. , , a. , , , .

+5

, , , 2-3 ...

(1) , . , , , - , , (, , ) .

(2) , ! APPEND, () . ! . , , SET-CDR! 'D .

(3) APPEND! NCONC Mac Lisp Common Lisp. ( ).

0

Source: https://habr.com/ru/post/1711828/


All Articles