JulioHerrlein Posted November 11, 2017 Share Posted November 11, 2017 Dear friends, I'm still learning. This is a simple thing. How can I put inside a function the name of a variable, like the example below. I want to do this: (gen-binary-row 12 '(0 2 5 7 8 11)) >> (1 0 1 0 0 1 0 1 1 0 0 1) But in this way: (setf binrow '(0 2 5 7 8 11)) (gen-binary-row 12 '(binrow)) What am I missing ? Thanks for help. Best, Julio Quote Link to comment Share on other sites More sharing options...
torstenanders Posted November 11, 2017 Share Posted November 11, 2017 You can define local variables within and outside functions with let. In principle, you can also use setf within a function, but then you are overwriting the value of a global variable. In most cases you want to avoid that. Functions that do not change anything outside them (so called side effects) are much safer. Both let and setf are explained in detail in the very informative online textbook Practical Common Lisp, chapter 6: http://www.gigamonkeys.com/book/variables.html. There you will also learn that Lisp actually distinguishes between lexical and dynamic variables; I was talking here about local and global variables instead for simplicity. In case this chapter covers something you don't follow, just go back a chapter or two and you will learn a lot :) Simple example: (defun my-function (x) (let ((y (+ x 1))) y)) (my-function 42) ; => 43 Best, Torsten JulioHerrlein 1 Quote Link to comment Share on other sites More sharing options...
AM Posted November 11, 2017 Share Posted November 11, 2017 But in this way: (setf binrow '(0 2 5 7 8 11)) (gen-binary-row 12 '(binrow)) What am I missing ? just do it like that: (setf binrow '(0 2 5 7 8 11)) (gen-binary-row 12 binrow) ;; your "binrow" is now a variable with a LIST as value ;; when you are writing '(binrow) it will be a LIST with the VALUE binrow (and not the values of "binrow") JulioHerrlein 1 Quote Link to comment Share on other sites More sharing options...
JulioHerrlein Posted November 11, 2017 Author Share Posted November 11, 2017 Dear Torsten, Thanks for your thoughtful answer. I'm going to try it. Best Julio Quote Link to comment Share on other sites More sharing options...
JulioHerrlein Posted November 11, 2017 Author Share Posted November 11, 2017 Thanks, André !! All the Best ! Julio Quote Link to comment Share on other sites More sharing options...
PatrickMimran Posted November 13, 2017 Share Posted November 13, 2017 Hello Julio if you are like me and you do not know lisp this is a very useful link where you can find the main lisp functions . I found it very useful. cl-reference-brian.pdf LispResumé.pdf AM and JulioHerrlein 1 1 Quote Link to comment Share on other sites More sharing options...
JulioHerrlein Posted November 14, 2017 Author Share Posted November 14, 2017 Great, rndrnd ! Thanks a LOT !!! BEst, Julio Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.