freenode/#lisp - IRC Chatlog
Search
10:01:26
feynhat
I am trying to use this library called "kenzo", which I have installed via quicklisp.
10:03:10
White_Flame
in the SLIME repl, kenzo:<TAB> to see what autocompletes is a good starting point to read
10:10:39
feynhat
phoe, was it really necessary though? I am sure people who are familiar with lisp would have figured this out quickly.
10:39:24
MichaelRaskin
The expectation is that either you defvar/defparameter the variable in advance, or create a local binding with let
11:03:43
jackdaniel
but if we assume that we ask about "potential" function, then question is meaningless
11:04:48
jackdaniel
asdf_asdf_asdf: defvar may be put as part of function body, but it is rarely what you want
11:05:27
jackdaniel
so if you use this variable elsewhere, then compilation will either fail or warn you about undefined symbol usage
11:07:55
jackdaniel
I think that you would benefit from reading some introductory material for programming (and if you have some experience, reading practical common lisp obok)
11:08:01
minion
asdf_asdf_asdf: please see pcl: pcl-book: "Practical Common Lisp", an introduction to Common Lisp by Peter Seibel, available at http://www.gigamonkeys.com/book/ and in dead-tree form from Apress (as of 11 April 2005).
11:22:03
Grue`
minion: memo for didi: you can avoid that with (funcall 'square ,y) because then you're only calling standard functions which cannot be redefined with flet, and 'square takes the global definition of square
14:47:07
dtw
dlowe: Here is my own quick hack that may need further polishing and thinking (function UNESCAPE-C-STRING): http://paste.debian.net/1074448/
14:57:16
vms14
https://stackoverflow.com/questions/48932481/lisp-macros-quotation-implementation-in-javascript
15:02:20
makomo
vms14: what you linked is an implementation of lisp (scheme) in javascript (not an actual feature of js)
15:02:23
vms14
also I want to check if it's true that when you learn Lisp, you'll change as a programmer
15:03:34
beach
vms14: I think your time will be better spent aiming to program sooner in Common Lisp.
15:04:49
vms14
Just need to focus on PAIP and I will, but I'm learning webdevelopment because I'm on a course
15:05:19
makomo
vms14: well, it's an implementation of the backquote mechanism but all of it is at the level of the implemented language (scheme), not js
15:06:39
makomo
it's a cl package/program that takes common lisp code as input and compiles it into js
15:09:13
dtw
pjb: Thank you. Those don't _seem_ to handle \\u and \\U codes but are most likely better than my quick hack.
15:16:11
makomo
pjb: as i learned myself the other day, you should probably handle the case of *READ-SUPPRESS* being bound to T within your reader macros
15:23:26
pjb
Because you're mutating the variable place1, which has nothing in common with the variable x in (let ((x '())) (push2 1 x) x)
15:26:33
beach
asdf_asdf_asdf: So if you understand that C code (you didn't say either way), then you know that add2(234, x) does not alter x.
15:27:19
beach
asdf_asdf_asdf: Similarly, in Common Lisp, if you call push2 with a variable as a second argument, that variable is not altered by the call to push2.
15:28:11
pjb
Instead, use: (defun push3 (item1 place1) (cons item1 place1)) (let ((x '())) (setf x (push3 42 x)) x)
15:29:18
pjb
(setf (aref (gethash :v *h*) (round (* 10 (sin theta)))) 42) this evalautes (gethash :v *h*) and (round (* 10 (sin theta))), but not (aref (gethash :v *h*) (round (* 10 (sin theta)))).
15:30:38
beach
Aruseus: But SETF itself does not evaluate to anything. It is not in a position to be evaluated.
15:32:46
beach
Common Lisp terminology is not very "fault tolerant", so it is important to use precise terminology.
15:38:47
_death
results---the multiple values[2] returned by the storing form for the last place, or nil if there are no pairs.
16:08:09
asdf_asdf_asdf
How change global variable inside function? (defvar *x* 5) (defun aaa (a) (setf a 6)) I want: *x* => 6. How it do? Thanks.
16:09:04
beach
asdf_asdf_asdf: You ask many questions, but you don't like to answer the ones that you are asked do you?
16:09:57
pjb
asdf_asdf_asdf: but actually, have a look at: https://www.informatimago.com/articles/usenet.html#C-like-pointers-in-Lisp
16:10:51
beach
asdf_asdf_asdf: OK, so if you do int x = 5; then void set_global_binding (int a) {a = 6;}
16:12:33
beach
asdf_asdf_asdf: Like C and most other languages, Common Lisp uses "call by value", meaning that argument expressions are evaluated before the function is applied to those values.
16:20:04
beach
asdf_asdf_asdf: pjb's examples are often too sophisticated for someone at your level.
16:22:17
asdf_asdf_asdf
(defun aaa (&treat_as_original a) (setf a 100)) => AAA. (defvar *x* 0) (aaa *x*) => 100 *x* => 100.
16:25:56
beach
asdf_asdf_asdf: Common Lisp has something called "macros" that can be used exceptionally for situations like that.
16:30:02
beach
asdf_asdf_asdf: As a first-order approximation, it is generally a bad idea to have variables in the caller be modified by a function call.
16:38:16
beach
asdf_asdf_asdf: If you tell me your native language, I will check and see if there is an equivalent page.
16:42:26
beach
asdf_asdf_asdf: Why not, there are plenty of smart Polish people here that could help you in your native language.
17:09:01
pjb
asdf_asdf_asdf: you need to quote the argument, since SET works on symbols. Didn't you read clhs set?
17:09:35
pjb
(defun set-dynamic-binding (var val) (set var val)) (defvar *x* 0) (set-dynamic-binding '*x* 42) *x* #| --> 42 |#
17:10:39
pjb
asdf_asdf_asdf: so it is possible. But you should not do that! First, you should not use global variables!
17:12:05
pjb
Then since arguments are passed by value, the language doesn't help you. Mutating the symbol-value slot, which is what SET does, the modern way to write (set var val) is (setf (symbol-value var) val), is just that. It's not a general solution. See the articles linked above for a general solution using closure. Which is sophisticated, and demonstrate again that you don't want to do that!
17:12:38
pjb
There's no point in reproducing the bad things of C in CL! Use CL to write BETTER programs! Don't try to mutate your arguments.
17:12:55
pjb
Instead, if you insist on using mutation, you can mutate the objects, the _values_ of your parameters.
17:13:52
pjb
(defun my-mutating-fun (v) (incf (aref v 0))) (defvar *vals* (make-array 3 :initial-element 0)) (my-mutating-fun *vals*) *vals* #| --> #(1 0 0) |#
17:22:51
c0mrade
I've made an IRC bot that prints to a dot matrix Star printer on its serial port at ##robot, everything you type there is printed to it and it's on Live Stream on YouTube at https://youtu.be/zwRL5V0XWQY
17:32:51
jcowan
Is it normal for interactive restart handling of USE-VALUE, STORE-VALUE, etc. to evaluate the expression read from the user that specifies the new value?
17:40:35
jcowan
I am specifying (and will be writing) a TTY-style interactor as part of the Scheme restart package I am also specifying.
17:41:26
jcowan
However, the current interactor will be held in a dynamic variable so that it can be replaced completely or rebound in a dynamic scope, such as by a TUI, GUI, or browser interactor.
19:08:13
rdap
I usually tend to come here when i find myself lost with a problem, and I guess this time is no exception.
19:12:32
beach
If you want me to try to help, you had better state your problem very soon, because I am about to quit in order to go spend my (admittedly small) family.
19:12:58
phoe
and if not, take your time, and let the rest of #lisp try to help while beach is off IRC
19:14:02
rdap
Oh, no worries. It's not urgent, and either I'll figure it out after reading more, or I'll have a more clearly stated problem.
19:17:37
phoe
rdap: when do you need the test to be evaluated and when do you need to break the loop?
19:18:14
rdap
i need the test to be evaluated before the loop runs (next), and for it to break there when the condition is met
19:24:48
pjb
(defmacro if (test consequent &optional alternative) `(loop repeat 1 if ,test do (progn ,consequent) else do (progn ,alternative)))
19:28:04
pjb
phoe: this is why sicl implements loop first, and then use it to implement the rest of CL ;-)
20:48:48
_death
(defun euler-1 () "Return the sum of all natural numbers below 1000 that are multiples of 3 or 5." (loop for x below 1000 when (or (multiple-of-p x 3) (multiple-of-p x 5)) sum x))
20:58:51
caltelt
The most straightforward way: (let ((threes (loop for x.....)) (fives (loop for x ...)) ...)