• Array constructor in Guile?

    From Axel Reichert@21:1/5 to All on Thu Apr 18 08:02:29 2024
    XPost: comp.lang.scheme

    Hello,

    Guile has a literal syntax for vectors

    #(1 2 3)

    so that

    (vector-ref #(1 (+ 2 3) 4) 1)

    returns

    (+ 2 3)

    but also a "constructor"

    (vector 1 (+ 2 3) 4)

    so that

    (vector-ref (vector 1 (+ 2 3) 4) 1)

    returns

    5

    There is a literal syntax for arrays, too,

    #2((2 1) (5 6))

    so that

    (array-ref #2((2 1) (5 6)) 1 1)

    returns

    6

    But I did not find an array "constructor" syntax that allows me to
    create an array such as

    #2((2 1) ((+ 2 3) 6))

    resulting in

    #2((2 1) (5 6))

    as above. How can I then create a "calculated" array, apart from filling
    an array with 0 first

    (define m (make-array 0 2 2))

    and then changing every element with

    (array-set! m 2 0 0)
    (array-set! m 1 0 1)
    (array-set! m (+ 2 3) 1 0)
    (array-set! m 6 1 1)

    ?

    Common Lisp's hyperspec show

    (make-array '(4 2 3) :initial-contents
    '(((a b c) (1 2 3))
    ((d e f) (3 1 2))
    ((g h i) (2 3 1))
    ((j k l) (0 0 0))))

    as an example.

    Pointers appreciated!

    Axel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Axel Reichert on Thu Apr 18 07:33:44 2024
    XPost: comp.lang.scheme

    On Thu, 18 Apr 2024 08:02:29 +0200, Axel Reichert wrote:

    But I did not find an array "constructor" syntax that allows me to
    create an array such as

    #2((2 1) ((+ 2 3) 6))

    resulting in

    #2((2 1) (5 6))

    (list->array 2 `((2 1) (,(+ 2 3) 6)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Axel Reichert@21:1/5 to Lawrence D'Oliveiro on Thu Apr 18 19:51:16 2024
    XPost: comp.lang.scheme

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    On Thu, 18 Apr 2024 08:02:29 +0200, Axel Reichert wrote:

    But I did not find an array "constructor" syntax that allows me to
    create an array such as

    #2((2 1) ((+ 2 3) 6))

    resulting in

    #2((2 1) (5 6))

    (list->array 2 `((2 1) (,(+ 2 3) 6)))

    Great, thanks, did not see this idea.

    Best regards

    Axel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Monnier@21:1/5 to All on Fri Apr 19 15:08:04 2024
    XPost: comp.lang.scheme

    #2((2 1) ((+ 2 3) 6))

    Hmm... I see they implemented quasiquotation for vectors but not
    for arrays:

    scheme@(guile-user)> `#(1 2 ,(+ 3 4))
    $1 = #(1 2 7)
    scheme@(guile-user)> `#2((1 2) (,(+ 3 4) 5))
    $2 = #2((1 2) ((unquote (+ 3 4)) 5))
    scheme@(guile-user)>

    I suggest you file a feature request for that.


    Stefan

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