Common Lisp Create matrix from the list -


i have: list lists of values ,e.g.

(list (list 1 2) (list 3 4 5) (list 1)) 

note: 2 dimensional array, cant structure this: (list (list (list 1))), in other words there can numbers\letters inside secondary list.

i want: create function, make list have same number of columns using nil's fill empty fields, if have list above input, output be:

((1 2 nil nil) (3 4  5  nil) (1 nil nil nil)) 

i sorry, has easy, novice in lisp , functional programming.

note: has use cons , append only, (this main problem) cons put each element inside different list , append remove nil's.

upd: have done said below, still have 1 problem

(defun findmlength (input)  (cond     ((null input) nil)     (t (and             (cond ((< maxlength (length (car input))) (setq maxlength (length (car input)))))             (findmlength (cdr input))))))  (defun makesquare (input rownumb) (prog (a)) (cond     ((null input) nil)     (t (and             (setq sqmatr (append sqmatr (list (append (car input) (make-list (- rownumb (length (car input))))))))             (makesquare (cdr input) rownumb))))) (setq sqmatr nil) (setq maxlength 0) 

the problem using global variables pass data, can clarify how can make them return variable them self?

a starting point homework: can use, each row, function make-list create list of n nil elements, n = desired lenght - length of row have. create list fill-up nils. can append initial row. example:

(append '(1 2) (make-list (- 4 (length '(1 2))))) => (1 2 nil nil)

do each row, appending result.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -