• Re: Simple problem in PG's ANSI Common Lisp

    From B. Pym@21:1/5 to paul graham on Thu Sep 26 02:17:26 2024
    XPost: comp.lang.scheme

    paul graham wrote:

    Or you could write

    (defun pos+ (lst)
    (let ((i -1))
    (mapcar #'(lambda (x) (+ x (incf i)))
    lst)))

    Btw, in Arc that would be

    (def pos+ (lst)
    (let i -1
    (map [+ _ (++ i)] lst)))


    Gauche Scheme

    (define (pos+ lst)
    (let1 i -1
    (map (~> (+ (inc! i))) lst)))

    Given:

    (define-syntax ->
    (syntax-rules ()
    [(_ x) x]
    [(_ x (y more ...) z ...)
    (-> (y x more ...) z ...)]
    [(_ x y z ...)
    (-> (y x) z ...)]))

    (define-syntax ~>
    (syntax-rules ()
    [(_ (func0 a ...) func ...)
    (lambda xs (-> (apply func0 (append xs (list a ...))) func ...))]
    [(_ func0 func ...)
    (lambda xs (-> (apply func0 xs) func ...))]))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Thu Sep 26 03:56:44 2024
    XPost: comp.lang.scheme

    On 2024-09-26, B. Pym <Nobody447095@here-nor-there.org> wrote:
    paul graham wrote:

    Or you could write

    (defun pos+ (lst)
    (let ((i -1))
    (mapcar #'(lambda (x) (+ x (incf i)))
    lst)))

    Btw, in Arc that would be

    (def pos+ (lst)
    (let i -1
    (map [+ _ (++ i)] lst)))


    Gauche Scheme

    (define (pos+ lst)
    (let1 i -1
    (map (~> (+ (inc! i))) lst)))

    Given:

    (define-syntax ->
    (syntax-rules ()
    [(_ x) x]
    [(_ x (y more ...) z ...)
    (-> (y x more ...) z ...)]
    [(_ x y z ...)
    (-> (y x) z ...)]))

    (define-syntax ~>
    (syntax-rules ()
    [(_ (func0 a ...) func ...)
    (lambda xs (-> (apply func0 (append xs (list a ...))) func ...))]
    [(_ func0 func ...)
    (lambda xs (-> (apply func0 xs) func ...))]))

    TXR Lisp:

    [mapcar + '(10 20 30) 0]
    (10 21 32)

    Given: TMF language, and that's it.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)