The First Use of Identity Function.

; I defined identity function long time ago in my library, "just
; in case." It, however, turned longer than I expected before I
; actually used it on natural way. Here is example, where I define
; my own combination of slice and sequence - where identity function
; is needed to compenstate for a difference between lists and
; strings. For example,
;
;
;        > (set 'L "ABC")
;        "ABC"
;
;        > (append (nth 0 L) (nth 1 L) (nth 2 L))
;        "ABC"
;
; But
;
;        > (set 'L '(1 2 3))
;        (1 2 3)
;
;        > (append (nth 0 L) (nth 1 L) (nth 2 L))
;
;        ERR: array, list or string expected : 1
;
;
; I have to "insert" one "list" if I want to use append:
;
; > (append (list (nth 0 L)) (list (nth 1 L)) (list (nth 2 L)))
; (1 2 3)
;
;
; I used it in my own definition of slice-sequence combination.
; I wanted this:
;
;    (slice-sequence "abcdefgh" 0 7 2) => "aceg"
;    (slice-sequence '(1 2 3 4 5 6 7 8) 0 7 2) => (1 3 5 7)
;
;
;



(set 'identity-function (lambda(x)x))

(set 'slice-sequence  
     (lambda(X)
        (apply append
              (map (lambda(i)((if (string? X)
                                  identity-function ; <==== HERE
                                  list)
                              (nth i X)))
                   (eval (cons 'sequence (args)))))))


; Yes, it is possible without identity-function, but it is, I think
; the most natural solution.

; My identity macro is still waiting.

No comments:

Post a Comment