libera/#commonlisp - IRC Chatlog
Search
1:09:30
asarch
How could I "put" the arguments of a function into a variable (e.g.: (format t "Se venden tacos") → (format foo))?
1:14:37
zacque
If foo = '(t "Se venden tacos"), then you can invoke `format` like (apply #'format foo)
1:24:03
zacque
What do you mean by "format should be out of the macro"? Can you move it out by yourself?
1:24:07
asarch
Let's say taco = t "Se venden ~d tacos". I would like to do: (format foo 10) → (format t "Se venden ~d~%" 10)
1:26:10
asarch
The args t and "Se venden ~d tacos" must be inside the foo var so I could easy type: (format foo 10)
1:49:40
imjim
I just ran that in `clisp` and got "FORMAT: The control-string must be a string, not 10"
1:52:02
zacque
asarch: You can either: (defmacro taco (num) `(format t "Se venden ~d tacos" ,num)) or (defun taco2 (num) (apply #'format (list t "Se venden ~d tacos" num)))
1:53:24
zacque
I think you should check out how to write a macro: https://gigamonkeys.com/book/macros-defining-your-own.html
1:53:49
asarch
Then I could easily write (defun beer(pizza) (format t "Se venden ~d tacos" pizza)) and then I just (beer 10), right?
2:08:08
asarch
I need something a la C' macros (with arguments and all) so I could write a full mixture of them: (format foo 10 bar baz(10)…) → (format t "Se venden ~d tacos" 10 …)
2:15:13
hayley
Better check https://gist.github.com/no-defun-allowed/4f0a06e17b3ce74c6aeac514281f350f
2:19:19
pillton
asarch: Macros in common lisp are nothing like C macros. The word macro in common lisp is actually short for macro function. Furthermore, there are actually many types of macros: reader macros, symbol macros and macro functions. Reader macros are executed when forms are being created from a character string or a character stream. Symbol macros and macro functions are expanded or invoked during compilation or evaluation.
2:36:17
hayley
There's no real definition for Lisp, so we can argue all day about what languages are "Lisp" or not. But most are terrible.
2:36:25
zacque
It only says "not all programming languages with S-exp are Lisp" but didn't say what exactly is Lisp to him/her
2:45:27
hayley
But I guess I am confused as to how we jumped to "Are you trying to write Lisp or C?"
2:47:19
zacque
My bad, I saw asarch said he wants "something a la C' macros" and in the format example, there is a "baz(10)"
2:49:02
hayley
Even if we had the right syntax, say (format foo 10 bar (baz 10) …) I don't see how you get to (format t "Se venden ~d tacos" 10 …), unless we use how the C preprocessor can replace a macro form with zero or multiple forms.
2:49:11
White_Flame
and shockingly you can just use normal lisp code to generate the expansion, instead of a separate template language ;)
3:11:50
phantomics
Asking this again as more are around: Has anyone ever used the Yale Haskell compiler? It's supposed to be implemented in CL but it appears to use Pseudoscheme, a Scheme implementation compiling to CL which I downloaded but couldn't get working, the build process is obviously very old
3:16:54
hayley
Still, <https://github.com/fiddlerwoaroof/yale-haskell-reboot> looks self-contained and doesn't mention a Pseudoscheme dependency.
3:19:39
hayley
Or rather <https://github.com/haskell-lisp/yale-haskell> looks like the original repository. Hm.
3:34:17
phantomics
I was thinking it could be neat to build an April-style interface to it so you could invoke Haskell in the middle of CL code
3:38:05
ldb
phantomics: YHC actually builds on T language, which is a dialect of lisp in the linage of Scheme but more focus on low level
3:44:28
ldb
They ported it to Common Lisp following an older standard (Lucid Common Lisp), and today's CL is no longer fully compatible with that.
3:45:44
phantomics
Gotcha, I'll try the fiddlerwoaroof reboot, wonder what it would take to get working again
3:49:02
ldb
The parser is actually not very good, and besides that it's all about high level code transformations, the runtime is just "lazy eval based on lisp closures".
4:17:25
Guest74
surprised nobody mentioned formatter. But who knows what was trying to be accomplished.
5:06:08
lispy
I keep getting an error on the last progn saying the variable "ELEMENT" is not defined (its supposed to be a plist)
5:08:09
lispy
if I give it something self evaluating (like 40) it works, but with the variable element it doesn't
5:11:47
lispy
I tried it again and it worked....... i think i maybe had the wrong region shaded and it caused the error, awkward.
5:19:38
beach
Your code is strange. It looks like in the `then' branch of the IF, you should be able to use T rather than MEMBER-P.
5:19:52
lispy
But when I call "(gethash '(COLORED "RED" :PRICE 15) *value-hash-table*" i just get NILs
5:21:18
beach
IF should be given a Boolean as a test, and the variable should not be called MEMBER-P.
5:22:00
beach
I am not talking about semantics. I am talking about the message you sent to people who read your code, in this case me.
5:22:30
lispy
Right, what would you suggest I use other than an if here ? if its either nil or some value
5:24:56
beach
If you have it there for readability, then extract each branch to a function, remove the PROGNs.
5:25:32
lispy
so the expectation is to have the if inline ? like (if () () ) or the issue is the blank line only ?
5:26:54
beach
Well, I don't really understand the code, so it is hard to say. I would probably abstract out the explicit hash tables and use a "dictionary"-type interface.
5:27:35
lispy
I have two hash tables one where the id is the key and the value is the value and another where its the opposite
5:31:48
beach
What makes you think two lists constructed at different times by the reader would be EQL?
5:32:35
lispy
Im kinda new to lisp, more used to other languages, I don't know what the difference between EQL and equal is exactly
5:45:06
hashfunc14a0
why is (/ #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F #x02) giving me 115792089237316195423570985008687907853269984665640564039457584007908834671663/2 ?
5:47:02
White_Flame
why isn't it sane? you're giving it precise numbers, it's giving you a lossless/precise result
5:47:45
White_Flame
clearly it's an odd number, so division by 2 would either yield an imprecise int, or imprecise float
5:48:33
aeth
if you don't want the exact answer, you have to tell it how to round. ROUND, TRUNCATE, FLOOR, CEILING. And if you want to turn it into a float, then FROUND, FTRUNCATE, FFLOOR, FCEILING
5:50:36
aeth
you'll get different answers if you do FLOAT or COERCE vs if you do it directly... probably a bit less efficient, perhaps with an intermediate bignum/bignum rational if the compiler doesn't expect it.
5:50:49
aeth
e.g. (coerce (/ #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F #x02) 'double-float)
5:50:52
aeth
vs. (fround #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F (coerce #x02 'double-float))
5:51:29
aeth
Same answer, but it doesn't have to be. FROUND defaults to single-float unless you specify double-float, so you do have to do some coerce, but nothing that a helper function can't fix
5:52:28
White_Flame
but still, I presume a large hex number would be the most desirable for this situation? then round + print in base 16
5:56:53
White_Flame
hashfunc14a0: if this is the case, recall that the reader simply reads the big hex number as an integer, passing no knowledge that it was in a hex representation originally
6:18:48
aeth
yes, you'd usually want to manually use FORMAT anyway, so you can get the right amount of leading 0s
6:20:48
jdz
hashfunc14a0: An illustrative question is: what would you expect an answer to the following expression to be: (+ (/ 1 3) (/ 2 3)), which can also be written as (+ 1/3 2/3)?
6:25:52
beach
It would be "interesting" if "sane" were to be defined as "what broken languages like C do".
6:54:47
ck_
not closely related, but I keep wanting to ask this question: where in the clhs, for example http://www.lispworks.com/documentation/HyperSpec/Body/22_cca.htm , does it say that you specify padchar 0 with '0 in the control-string?
6:58:08
semz
"Prefix parameters are notated as signed (sign is optional) decimal numbers, or as a single-quote followed by a character."