How to resolve the algorithm Array concatenation step by step in the Scheme programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Array concatenation step by step in the Scheme programming language
Table of Contents
Problem Statement
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Array concatenation step by step in the Scheme programming language
Source code in the scheme programming language
; in r5rs, there is append for lists, but we'll need to define vector-append
(define (vector-append . arg) (list->vector (apply append (map vector->list arg))))
(vector-append #(1 2 3 4) #(5 6 7) #(8 9 10))
; #(1 2 3 4 5 6 7 8 9 10)
(use gauche.array)
(define (print-matrix m)
(define row-num #f)
(array-for-each-index m
(lambda (row col)
(when (and row-num (not (= row-num row))) (newline))
(format #t "~a " (array-ref m row col))
(set! row-num row)))
(newline))
(define a
#,(<array> (0 3 0 2)
a b
c d
e f))
(define b
#,(<array> (0 3 0 2)
1 2
3 4
5 6))
(print-matrix (array-concatenate a b))
(print-matrix (array-concatenate a b 1))
You may also check:How to resolve the algorithm Speech synthesis step by step in the GlovePIE programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Non-continuous subsequences step by step in the Ruby programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the Raku programming language