Question: LISP how to write this function without using LOOP

Question

LISP how to write this function without using LOOP

Answers 1
Added at 2016-12-26 12:12
Tags
Question

i wrote this function but i have been told i can't use the loop inside of it, i have no idea how to modify it in order to remove the loop. any suggestion?

(defun function (P VariableValues)
(let* ((M (mono P))
        (VariableNames (variables P))
        (VariableDict (loop for x in VariableNames for y in VariableValues collect (cons x y)))
        (Valorizzati (mapcar (lambda (x) (applica-valori VariableDict x)) M))
    ) 
  (if Valorizzati
      (+ (car Valorizzati) (recursive-sum (cdr Valorizzati))) 
    0)))
Answers to

LISP how to write this function without using LOOP

nr: #1 dodano: 2016-12-26 12:12

You can use mapcar for that:

(mapcar #'cons '(a b c) '(1 2 3))
;; ==> ((a . 1) (b . 2) (c . 3))
Source Show
◀ Wstecz