themsay has quit [Remote host closed the connection]
themsay has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
libertyprime has joined #lisp
wxie has joined #lisp
playful-owl has quit [Quit: leaving]
<phoe>
pjb: yep, I found it in serapeum as well. It's a one-liner using LOOP.
robdog has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
jack_rabbit_ has joined #lisp
robdog has joined #lisp
varjag has quit [Ping timeout: 250 seconds]
robdog has quit [Ping timeout: 250 seconds]
Lord_of_Life_ has joined #lisp
elderK has joined #lisp
robdog has joined #lisp
Lord_of_Life has quit [Ping timeout: 245 seconds]
Lord_of_Life_ is now known as Lord_of_Life
robdog has quit [Ping timeout: 250 seconds]
ym555 has quit [Ping timeout: 250 seconds]
robdog has joined #lisp
oystewh has joined #lisp
robdog_ has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
Oladon has quit [Quit: Leaving.]
tharugrim has quit [Quit: WeeChat 2.4]
robdog_ has quit [Ping timeout: 250 seconds]
jack_rabbit_ has quit [Ping timeout: 250 seconds]
pankajgodbole has joined #lisp
karlosz has joined #lisp
robdog has joined #lisp
lumm has quit [Remote host closed the connection]
robdog has quit [Ping timeout: 250 seconds]
ciaranb has quit [Ping timeout: 246 seconds]
Inline has joined #lisp
robdog has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
lucasb has quit [Quit: Connection closed for inactivity]
makomo has quit [Ping timeout: 250 seconds]
Oladon has joined #lisp
robdog has joined #lisp
libertyprime has quit [Ping timeout: 250 seconds]
Essadon has quit [Quit: Qutting]
vibs29 has quit [Read error: Connection reset by peer]
robdog has quit [Ping timeout: 250 seconds]
vibs29 has joined #lisp
jmercouris has joined #lisp
<jmercouris>
I have (flet ((func (x) (print x))) (mapcar func listz)) and it complains that func is unused
<jmercouris>
"deleting unused function" when compiling in sbcl
<jmercouris>
must I use #'?
<jmercouris>
why is it sometimes to only quote a symbol rather than using the explicit function notation
<jmercouris>
is it another example of a so called "forgiving" function, like string-downcase?
robdog has joined #lisp
<didi>
jmercouris: Others can explain it in more details, but FLET dines local named functions. By calling (mapcar 'func listz), you're passing a function designator, not the function.
<didi>
s/dines/defines
<didi>
"The names of functions defined by flet are in the lexical environment; they retain their local definitions only within the body of flet."
<jmercouris>
so (quote func) is only a symbol that designates a ffunction rather than #' which somehow explicitly notes a function
<jmercouris>
is that what you are saying?
<didi>
jmercouris: It is.
<jmercouris>
I wonder why some functions accept function designators sometimes
<jmercouris>
or rather symbols that are pointing to functions
<jmercouris>
which is I guess what we mean when we say "function designators"
robdog has quit [Ping timeout: 250 seconds]
<White_Flame>
(eq (function +) (symbol-function '+)) => T
PuercoPope has joined #lisp
<jmercouris>
I see
<White_Flame>
since FUNCALL and APPLY accept function designators, anything that falls through to that implicitly supports them
<jmercouris>
yes
<White_Flame>
in your original question, mapcar can't see the lexical binding of FUNC, and nothing you pass to it links to it
<didi>
jmercouris: I learned to use #' after a COMPLEMENT failed with a symbol deep inside my program.
<White_Flame>
also #' is probably a bit faster
<jmercouris>
why can it not see the lexical binding?
<jmercouris>
is flet a macro?
<didi>
jmercouris: Lexical binding it about space.
<jmercouris>
didi: can you please rephrase
<didi>
jmercouris: CLtL2 has a nice chapter about it.
<didi>
jmercouris: Read chapter 3. Scope and Extent. It will do a better job than I will ever be able to.
<jmercouris>
CLtL2 ? common lisp the language 2?
<didi>
jmercouris: Indeed.
<jmercouris>
ok, will do
<jmercouris>
same site I was able to get gentle introduction to symbolic computation
hyero has quit [Remote host closed the connection]
<jmercouris>
that was a good read
<jmercouris>
though I did not enjoy the recursion section of the book
<jmercouris>
no matter how much I practice recursion, I just don't enjoy it
<didi>
jmercouris: It grows on you. Specially while using lisp.
benjamin-l has joined #lisp
<jmercouris>
maybe in a few years
<jmercouris>
but I've been a computer scientist for about 10 years now
<jmercouris>
and I still don't enjoy it
<jmercouris>
only have been doing lisp for about 2 years though
<didi>
jmercouris: That's fine. I still bet you will enjoy it.
karlosz has quit [Quit: karlosz]
<White_Flame>
jmercouris: did you also get an error about FUNC being unbound when you're passing it into mapcar?
<jmercouris>
no, it was quote
<White_Flame>
ah, ok
<jmercouris>
if I remove the quote, of course
<White_Flame>
so you're just passing a symbol. Mapcar can't see anything about that symbol besides its toplevel symbol-value, symbol-function etc
<White_Flame>
your flet is only lexically visible within the flet scope
<jmercouris>
write, and since it is lexically bound, and not toplevel, it doesn't work
<jmercouris>
damnit you typed faster than me
<White_Flame>
the call to mapcar is outside taht
<jmercouris>
yes, I get it now
<jmercouris>
thanks for clarification and confirmation though :)
<jmercouris>
as an aside, White_Flame , what is your typing speed?
<White_Flame>
this keyboard I'm on now sucks, but I've hit 200wpm
<jmercouris>
I see, so you are a little bit faster than me
<jmercouris>
my peak has been around 180, and I can average 100-120 for sustained periods of time
<jmercouris>
the problem usually becomes thinking that fast :D
<jmercouris>
Its on my reading list, probably a bit too high level for me at a cursory glance
<jmercouris>
but I'll take a look when I have a moment
<pjb>
let <-> flet bound <-> fbound var <-> (function f) (funcall var) <-> (f)
<pjb>
jmercouris: you should read it now.
<spacedbat>
the price of a lisp-2
<pjb>
Actually, you should have read it yesterday, since today you're asking about it!
robdog_ has quit [Ping timeout: 250 seconds]
ebrasca has quit [Remote host closed the connection]
<jmercouris>
pjb: I would, but I have some deadlines, its also late o'clock
robdog has joined #lisp
<PuercoPope>
There is an advantage to using the symbol instead of the function itself. Because the symbol is looked up when the code is run if you redefine the function you'll get the new function instead of keeping a reference to the old function object until you recompile the call sites as well
<didi>
spacedbat: More like lisp-7 /me channels PAIP
<jmercouris>
pjb: I thought you woke up early, what time do you sleep?
<pjb>
random, basically.
<didi>
PuercoPop: I miss that.
<jmercouris>
PuercoPop: Yes, that's why I usually prefer quote to handle redefinitions
robdog has quit [Ping timeout: 250 seconds]
karlosz has joined #lisp
MightyJoe has quit [Ping timeout: 255 seconds]
cyraxjoe has joined #lisp
themsay has quit [Read error: Connection reset by peer]
themsay has joined #lisp
themsay has quit [Read error: Connection reset by peer]
themsay has joined #lisp
robdog has joined #lisp
orivej has quit [Ping timeout: 246 seconds]
robdog has quit [Ping timeout: 250 seconds]
robdog has joined #lisp
keep_learning_M has quit [Ping timeout: 245 seconds]
zotan has quit [Ping timeout: 257 seconds]
zotan has joined #lisp
nicdev has quit [Quit: ERC (IRC client for Emacs 26.1)]
nicdev has joined #lisp
keep_learning_M has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
robdog has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
keep_learning_M has quit [Ping timeout: 246 seconds]
jmercouris has quit [Remote host closed the connection]
keep_learning_M has joined #lisp
robdog has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
FreeBirdLjj has joined #lisp
FreeBirdLjj has quit [Read error: Connection reset by peer]
<gilberth>
didi: Don't ask me. I just was kidding, because Schemers think our macro system is dirty.
<didi>
Ah...
<didi>
I see.
<gilberth>
didi: Perhaps it can, I tried to be funny in a way. Though I don't remember much Scheme. I love my dozen namespaces.
* didi
hugs lisp
Oladon has quit [Quit: Leaving.]
<gilberth>
didi: Any luck with your compiler macro?
impulse has joined #lisp
<didi>
gilberth: Nope. I tried reading CLtL2, but this stuff is hard. I guess I'll stay with (defmacro mfn (x) (fn ,x)) for now.
keep_learning_M has quit [Ping timeout: 255 seconds]
<gilberth>
didi: OK, if that works for you, the better. But dig the different evaluation times when you have time for that.
<didi>
gilberth: Thanks, I will.
<gilberth>
didi: And nobody ever claimed that Lisp is easy. :)
<didi>
gilberth: They said it had no syntax!
<gilberth>
didi: But it is a lot of fun once you master it.
keep_learning_M has joined #lisp
<didi>
*nod*
<gilberth>
didi: Well, for the proper definition of syntax.
<didi>
gilberth: Always the small font... ;-)
<gilberth>
didi: Xach said I am olde, so I use a larger font these days.
MightyJoe has joined #lisp
cyraxjoe has quit [Ping timeout: 246 seconds]
<PuercoPope>
is there any reason to prefer ash vs dpb/ldb when 'buidling' integers from octets? Most code I've found in the open uses ash but I'm inclined to think it is more a more a consquence of familiarity with C
<gilberth>
I prefer DPB and LDB.
<gilberth>
And here is why: The exact "subsequence" of bits named the byte is explicitly mentioned in the involving BYTE.
robdog has joined #lisp
torbo has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
smasta has joined #lisp
smasta has quit [Ping timeout: 255 seconds]
<PuercoPope>
its also more 'clear'. "I want to put this bytes here" instead of add this number and move them to the right X times
<PuercoPope>
I was surprised to learn that ldb only works on integeres. Is there a reason why it couldn't work on floats?
karlosz has quit [Quit: karlosz]
<gilberth>
I agree. And size and position of the byte is in one place.
<gilberth>
You also could do, say, (DEFCONSTANT +OPCODE-BYTE+ (BYTE 4 28)) and later just (LDB +OPCODE-BYTE+ X)
<gilberth>
With ASH and LOGAND, you would need +OPCODE-SHIFT+ and +OPCODE-MASK+.
<gilberth>
All IMHO.
<gilberth>
PuercoPope: Would (DPB 1.0 (BYTE 1 1000) 1.0) work?
dddddd has quit [Remote host closed the connection]
<gilberth>
To answer the original question: Yes, I believe DPB/LDB is "cleaner", but people are just used to ASH/LOGAND/LOGIOR because of C idioms.
caltelt_ has quit [Ping timeout: 250 seconds]
<PuercoPope>
gilberth: no, because the spec says the first and last argument must be integers
<PuercoPope>
is there a different encoding to floats than ieee-754?
<gilberth>
You were asking, why it wouldn't work on floats. So imagine it would, what would happen?
<gilberth>
There were quite a lot different encodings.
<gilberth>
ANSI CL specifically does not stick to any particular float encoding. Even decimal floats are possible. See INTEGER-DECODE-FLOAT or what ever that is called.
<gilberth>
IIRC the 8087 also has some 80-bit floating point format.
* gilberth
is olde.
<PuercoPope>
I as unware there were different encoding to floats, in that case it doesn't make sense for ldb to work on floats.
<gilberth>
Did you imagine for LDB and DPB to work on the underlying bit pattern? Instead of the mathematical value?
Aruseus has quit [Remote host closed the connection]
<gilberth>
As in: I have a double --- that are 64 bits --- here and there is the exponent and there is the sign?
polezaivsani has quit [Remote host closed the connection]
<gilberth>
And then the IEEE format is nuts anyway, I hope we replace it by something more reasonable.
notzmv has quit [Ping timeout: 245 seconds]
didi has left #lisp ["O bella ciao bella ciao bella ciao, ciao, ciao."]
<gilberth>
But then the interface of DECODE-FLOAT and friends is pretty nice.
fouric has joined #lisp
<PuercoPope>
gilberth: yeah, like single-float had only one representation. But if it is like chars, it is a good idea to not leak the concrete encoding into the rest of the language
smasta has joined #lisp
<gilberth>
PuercoPope: Correct. That way to extend the character datatype to 29-bit code points didn't hurt.
<gilberth>
It was a pain in the late 90'ies though, as most Lisp still where 8-bit there.
<gilberth>
So, when we make contact to aliens, which have their own 40-bit character set, we could easily extend the character data type with no damage done. :-)
smasta has quit [Ping timeout: 272 seconds]
<gilberth>
Actually I love that. We run code, which is 30 years old or older. And it'll still run in 30 years.
<gilberth>
C is not like that. Try to compile system 7 code --- no luck.
<PuercoPope>
One problem with old code is loading it. Not all old code used mkdefsystem which translates more or less to ASDF. For example loading op5 in SBCL is not straighforward. But I agree its nice for code not to bitrot
orivej has joined #lisp
<gilberth>
Well, that is loading "only". Look at CXML for example. I started to write that some 20 years ago and people still use that. Though I have no idea who maintains it right now.
<PuercoPope>
There are two versions of it right now
<gilberth>
Two?!
<PuercoPope>
the Sharplispers one and the fork FXML
* gilberth
is puzzled.
<gilberth>
Why?
<PuercoPope>
by Ruricolist, which was used in a comercial product until recently
<PuercoPope>
because it was unmantained so the author didn't know where to submit patches to
<gilberth>
People were unhappy with SGML, which I can understand.
<PuercoPope>
I haven't bothered to learn texinfo and now that you can generate info manuals from Org mode I don't think I'll ever will. Its a pitty because modern documentation tools pays little attention to things like indexes
<gilberth>
Do we need indexes, when we have a proper search function?
orivej has quit [Ping timeout: 246 seconds]
<PuercoPope>
It helps w/ autocomplete at the very least. But having indexes is a prerequiste to having proper search
<PuercoPope>
(I didn't mean index section, just indexes as pre-processing the data)
<gilberth>
What I find more important is the term/concept idea. We have that in the CLIM spec. It says, say, "The argument x must be a foo."
<gilberth>
Then "foo" is a term and it should link to a definition, what a foo is.
<no-defun-allowed>
You need to defvar at the top level, ie outside any functions.
nalkri has joined #lisp
<phoe>
How do I check if two values are both true or both false?
<phoe>
That would be a XNOR operation.
<jackdaniel>
how about (eq (not a) (not b)) ?
<jackdaniel>
phoe: ↑
<nalkri>
Can't is just be (not (xor a b))?
<nalkri>
Only, like, assume I used English
<jackdaniel>
nalkri: is there xor operation in cl package?
<nalkri>
Yes I think so
<nalkri>
Sorry, I'm just barging in without context though I'll be shush
<jackdaniel>
I'm only aware about numerical operations (logxor and bit-xor)
<nalkri>
I shouldn't have said anything, just ignore me :)
kushal has quit [Remote host closed the connection]
kushal has joined #lisp
wxie has quit [Remote host closed the connection]
wxie has joined #lisp
<phoe>
jackdaniel: that's good, thanks
<phoe>
jackdaniel: alexandria:xor
<asdf_asdf_asdf>
Why variable global can't be inside function, only outside function?
<jackdaniel>
phoe: I was asking about cl package. I'm sure there is some serapeum:xnor too
<phoe>
jackdaniel: there's none
<jackdaniel>
but if we assume that we ask about "potential" function, then question is meaningless
<jackdaniel>
because you may always just put the name of said function and pass arguments
<jackdaniel>
asdf_asdf_asdf: defvar may be put as part of function body, but it is rarely what you want
<jackdaniel>
because such defvar will take effect only *after* executing said function
<jackdaniel>
so if you use this variable elsewhere, then compilation will either fail or warn you about undefined symbol usage
<asdf_asdf_asdf>
jackdaniel, so I must have variable outside function, to works?
<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)
<jackdaniel>
minion: please tell asdf_asdf_asdf about pcl
<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).
<phoe>
asdf_asdf_asdf: (defun x () (let ((x 0)) (+ x 1)))
smasta has joined #lisp
smasta has quit [Ping timeout: 250 seconds]
nowhere_man has quit [Ping timeout: 258 seconds]
p9fn has quit [Ping timeout: 264 seconds]
<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
<minion>
Remembered. I'll tell didi when he/she/it next speaks.
<beach>
asdf_asdf_asdf: Do you understand that C code? (I hope the syntax is right).
robdog has joined #lisp
<asdf_asdf_asdf>
beach, thanks. Really is it local variable not global. Already works.
vibs29 has joined #lisp
<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.
<asdf_asdf_asdf>
I know, thanks. Variable must be global, to change value.
<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.
<beach>
asdf_asdf_asdf: Yes, but that is not a good way to program.
<beach>
asdf_asdf_asdf: Instead, use the values that functions return.
<Aruseus>
beach, but setf evaluates to the new value of place1, right?
<pjb>
since SET only works on special variables (dynamic bindings).
elazul has quit [Ping timeout: 246 seconds]
<beach>
asdf_asdf_asdf: OK, so if you do int x = 5; then void set_global_binding (int a) {a = 6;}
<beach>
What do you get?
nullheroes has quit [Quit: WeeChat 2.3]
<beach>
... if you call set_global_binding(x)
<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.
smasta has joined #lisp
agspathis has joined #lisp
agspathis has quit [Client Quit]
agspathis has joined #lisp
robdog has joined #lisp
smasta has quit [Ping timeout: 250 seconds]
<asdf_asdf_asdf>
Not works: ... (set var value).
<beach>
asdf_asdf_asdf: pjb's examples are often too sophisticated for someone at your level.
tharugrim has joined #lisp
<asdf_asdf_asdf>
(defun aaa (&treat_as_original a) (setf a 100)) => AAA. (defvar *x* 0) (aaa *x*) => 100 *x* => 100.
Ukari has joined #lisp
Josh_2 has quit [Read error: Connection reset by peer]
robdog has quit [Ping timeout: 268 seconds]
warweasle has quit [Quit: spank me]
<beach>
asdf_asdf_asdf: How about just accepting that it is not possible.
<beach>
asdf_asdf_asdf: Even if it were possible, you don't want to program that way.
<beach>
asdf_asdf_asdf: Common Lisp has something called "macros" that can be used exceptionally for situations like that.
<beach>
asdf_asdf_asdf: For example, SETF is such a macro. It is not a function.
<beach>
asdf_asdf_asdf: But this is way too early in your studies to worry about.
<pjb>
asdf_asdf_asdf: in C, you use & to pass the address of the place you want to mutate.
<pjb>
asdf_asdf_asdf: so it is possible. But you should not do that! First, you should not use global variables!
d4ryus has joined #lisp
<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!
<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.
<pjb>
Instead, if you insist on using mutation, you can mutate the objects, the _values_ of your parameters.
<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
jcowan has joined #lisp
<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?
Jesin has quit [Quit: Leaving]
pankajgodbole has quit [Remote host closed the connection]
<_death>
jcowan: yes
<jcowan>
Thanks.
<phoe>
jcowan: if the user doesn't want it evaluated they can always quote it
* jcowan
nods.
<phoe>
it's harder the other way around
<jcowan>
I am specifying (and will be writing) a TTY-style interactor as part of the Scheme restart package I am also specifying.
<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.
grewal has joined #lisp
<asdf_asdf_asdf>
Thanks for help p-j-b.
Jesin has joined #lisp
zotan has quit [Ping timeout: 258 seconds]
zotan has joined #lisp
agspathis has quit [Quit: ERC (IRC client for Emacs 27.0.50)]
smasta has joined #lisp
smasta has quit [Ping timeout: 250 seconds]
elem6 has joined #lisp
ym has quit [Remote host closed the connection]
rozenglass has quit [Read error: Connection reset by peer]
rozenglass has joined #lisp
random-nick has quit [Read error: Connection reset by peer]
elem6 has quit [Ping timeout: 250 seconds]
abhixec has joined #lisp
elazul has joined #lisp
Oladon has joined #lisp
robdog has joined #lisp
robdog has quit [Ping timeout: 250 seconds]
vibs29 has quit [Ping timeout: 245 seconds]
smasta has joined #lisp
vibs29 has joined #lisp
hiroaki has joined #lisp
smasta has quit [Ping timeout: 246 seconds]
rdap has joined #lisp
<rdap>
o/
<beach>
Hello rdap.
<rdap>
And hello to you as well, beach.
<beach>
rdap: Are you new here? I don't recognize your nick.
<rdap>
I've been here off and on in the past, but I've never really been a regular.
<beach>
I see.
<rdap>
I might have been using the nick 'caffe' at the time
<beach>
That one I think I have seen.
<rdap>
I usually tend to come here when i find myself lost with a problem, and I guess this time is no exception.
<beach>
Uh, oh.
<rdap>
I haven't given up reading just yet, so don't worry.
<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.
<beach>
But I guess others will help as well.
<phoe>
and if not, take your time, and let the rest of #lisp try to help while beach is off IRC
<phoe>
oh right exactly that
<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.
<White_Flame>
I thought sicl implemented everything assuming everything else exists
<rdap>
there's probably a more elegant way to do it
<phoe>
rdap: you don't want DEFVAR in there
<phoe>
use LET instead
<phoe>
I mean, DEFPARAMETER
<_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))
<phoe>
(multiple-of-p x 3) === (= 0 (mod x 3))
elazul has quit [Quit: leaving]
<no-defun-allowed>
zerop?
<phoe>
even better
<rdap>
phoe: i tried to do it with let, but wasn't able to quite understand it
<phoe>
(let ((x 10) (y 20)) (+ x y)) ;=> 30
<rdap>
yeah, i saw examples like that but couldn't figure out how to apply it to this
c0mrade has quit [Ping timeout: 272 seconds]
angavrilov has quit [Remote host closed the connection]
<pjb>
<rdap> i was going to say, that's not right :P
<pjb>
<pjb> Yes.
<pjb>
#lisp But it's nice :-)
<pjb>
Oops.
<_death>
since you're treating them as sets, you can use union
<pjb>
But union doesn't ensure unicity.
kushal has quit [Remote host closed the connection]
kushal has joined #lisp
<_death>
"If there is a duplication between list-1 and list-2, only one of the duplicate instances will be in the result. If either list-1 or list-2 has duplicate entries within it, the redundant entries might or might not appear in the result."
<_death>
so in this case it would work
<pjb>
Yes, so from iota this should work. (reduce '+ (union (mapcar (times 3) (iota 20)) (mapcar (times 5) (iota 20)) )) #| --> 1430 |#
<jcowan>
There's a Scheme library that provides both behaviors (treat all elements in an input list as distinct, treat elements in a list as possibly nondistinct). It would be trivial to translate it.
andrei-n has quit [Remote host closed the connection]
torbo has joined #lisp
ltriant has joined #lisp
<grewal>
Isn't union inherently slow?
<grewal>
(- (+ (loop for x from 0 below 1000 by 3 summing x) (loop for x from 0 below 1000 by 5 summing x)) (loop for x from 0 below 1000 by 15 summing x))
random-nick has joined #lisp
<_death>
grewal: since the answer is fixed, just use 233168
lerax has joined #lisp
<grewal>
_death: (defun add-multiples-below (p1 p2 bound) "TODO: implement values for other arguments" 233168)
<grewal>
like that :p
bobby has quit [Remote host closed the connection]
bobby has joined #lisp
<aeth>
The programmatic solution to _death's problem: (defun foo () #.(- (+ (loop for x from 0 below 1000 by 3 summing x) (loop for x from 0 below 1000 by 5 summing x)) (loop for x from 0 below 1000 by 15 summing x))) (disassemble #'foo) (foo)
<aeth>
You get a function that constantly returns 233168 with no computation, but *you* don't have to compute it and hardcode it yourself!