<lisp123>
Closest I got was this comment: "To make the tokens 00 and 0 parse as different objects, you have to manipulate the Lisp reader. This is advanced stuff, I doubt that your instructor expects you to use it at this point."
<phoe>
lisp123: "you can't"
<phoe>
00 and 0 are the same integer in Common Lisp
<phoe>
you can't force Lisp to tell them apart
<pjb>
Well, you can force it with \00 vs \0
<lisp123>
Is there a way to manipulate the lisp reader to read '(a b 00 1) as a string ("'(a b 00 1)")
<pjb>
Another way would be to use "00" vs "0" since they talk about "letter" ("characters") and and "digits"….
<phoe>
lisp123: no, unless you actually use a custom reader
<pjb>
lisp123: yes: use read-line instead of read.
<lisp123>
(with-new-reader '(a b 00 1)) --> "'(a b 00 1))"
<phoe>
lisp123: no, because by the time you try to call WITH-NEW-READER the list '(a b 00 1) is already read
<phoe>
pjb: I think that lisp123 wants (my-fun '(a b c 0 0 1)) to succeed but (my-fun '(a b c 00 0 1)) to fail
<phoe>
which is undoable, even if we are allowed to use read-line
<phoe>
unless we actually pull in stuff like eclector which would be insane for a homework assignment
<beach>
The person posting clearly says that the list should contain characters and digits, so the solution is to use characters and digits, and not symbols and numbers.
<lisp123>
phoe: Nah, I want (with-new-reader '(a b 00 1)) --> "'(a b 00 1))" or something like that. After which a custom parser can handle the question in the reddit thread
<hayley>
A hypothetical WITH-READER macro could not be implemented as a macro.
<beach>
lisp123: Listen to phoe. You can't do that because the list will already have been read.
<lisp123>
beach: hayley: Thanks, got it
jmdaemon has quit [Ping timeout: 250 seconds]
<jackdaniel>
#with-reader '(m a k u m b a j a)
<pjb>
Instead of a reader macro on # you can have it on ( and write (with-reader '(m a k u m b a j a)).
<pjb>
Once you write this reader macro, it makes no difference.
<jackdaniel>
no no, I'm suggesting updating the standard to include #with-reader
<phoe>
I have been away for a few months, I see that #commonlisp has not really changed during that time
<phoe>
:D
<pjb>
stability is our motto.
<jackdaniel>
lisp is not deader than usual if that's what you are poking at
<lisp123>
phoe: glad to have you back
<phoe>
jackdaniel: it still has no new standard too!
<phoe>
lisp123: but yes, seriously now - try to understand the way in which Lisp processes code, in particular, the reading phase - you'll see that, during the process of reading your program's input data, this is where the string "00" gets turned into the integer 0
<phoe>
which means that, after the reading phase, any distinction between 00 and 0 disappears
<phoe>
which is why you need to use a different data type if you want 00 and 0 to be different - like e.g. strings, as I suggested earlier on reddit
<pjb>
lisp123: it's basically a question of types and data representation.
<pjb>
lisp123: don't use integers to represent chains of characters!
<pjb>
use strings.
lisp123 has quit [Remote host closed the connection]
<pjb>
The error is writting '(a b 00 1) instead of '("a" "b" "00" "1")
lisp123 has joined #commonlisp
<phoe>
I assume the real error is the teacher treating the REPL as some sort of line input
<lisp123>
pjb: Yes. I was just curious on whats possible. Reading the KMP article now
<phoe>
if you were writing this program in C then you'd most likely use getline() or something, at which point you are dealing with strings
<phoe>
if you are writing in Lisp then the sorta-natural way is to use the REPL, at which point you are NOT dealing with strings but native Lisp data types
<phoe>
if you write stuff like A B C 0 00 1 into stdio, then obviously you can capture the lone 00 in there
<phoe>
but if you write it into the REPL then the Lisp reader operates on this data before passing it to your program, and after this operation you can no longer see the 00
<lisp123>
phoe: Thanks
<phoe>
one solution is to use strings as native Lisp types
<phoe>
another is to modify your program so it reads its input in the non-really-Lispy way, which is, from standard input - hence giving it the same sort of input that C programs have
tyson2 has joined #commonlisp
<phoe>
yet another one is to use a custom reader for reading Lisp stuff, at which point you're way too deep into the rabbit hole to call it homework
<phoe>
and if you're just starting out with Lisp then it's not the hole you want to be in
<lisp123>
actually no, that article doesn't suggest that
<lisp123>
its close but not the same...so maybe it is indeed impossible to read a lisp form as a string
okflo has quit [Quit: ZNC 1.6.3+deb1ubuntu0.2 - http://znc.in]
<phoe>
I'd be wary of the word "impossible" because Lisp is so damn programmable that someone might actually write a Lisp hack that does exactly that
<lisp123>
Is it possible to add a read macro on "("
<phoe>
but it's certainly hard and non-standard enough
<jackdaniel>
the very fact that you may supply your own reader /before/ reading the file makes it very much doable
<jackdaniel>
it is, because you don't always need to modify the standard reader table, you may come up with your own
<lisp123>
and if the next symbol is with-string-reader, it will go down the path of reading as string and otherwise go down the normal path?
<lisp123>
jackdaniel: Ah makes sense
<jackdaniel>
check out the library named readtables - very useful for local dsls
<phoe>
something like that, yes, with the main problem being "when exactly do I stop reading the form as a string"
<lisp123>
phoe: yep
<contrapunctus>
phoe: welcome back \o/
<lisp123>
ok i'll shut up now, my curiousity is satisfied on this topic
<phoe>
the main issue, I guess, is that READ will not return the number of characters it read to build the object
<phoe>
so you cannot duplicate the stream, read an object, count off "this many characters" and get a subsequence
<phoe>
but I assume you could build a Gray stream that does it for you and pass that stream to READ
<phoe>
for every char that you read, buffer it in some internal string buffer; finally, when you're done reading, return the buffer, bam, here's the string version of whatever you just read
<lisp123>
Nice
<phoe>
so a reader macro on #\(, a way to recognize the special symbol, a Gray stream which memorizes string versions of the objects being read
<lisp123>
perhaps the assignment was from MIT ;)
<phoe>
and then your actual code that tries to parse this string representation, along with all the funny things that might happen along the way, like, "is '(A B C 0 0 #.(+ 2 2)) a valid plate?"
<jackdaniel>
then it would be in python or javascript; n.b I appreciate this shameless honesty - "I have an assignment and please solve it for me", pretty trustwothy fellow! ,)
<phoe>
easy, just write a javascript interpreter in lisp and then solve your problem
<phoe>
contrapunctus: thanks
attila_lendvai has quit [Ping timeout: 268 seconds]
cercopith_ has joined #commonlisp
cercopith has quit [Ping timeout: 265 seconds]
<_death>
make-echo-stream ?
cercopith_ has quit [Ping timeout: 265 seconds]
<phoe>
yes
cercopith has joined #commonlisp
cercopith has quit [Remote host closed the connection]
* phoe
grumbles at a DEFINE-PACKAGE edge case that he just hit
srji has quit [Quit: leaving]
razetime has quit [Ping timeout: 268 seconds]
srji has joined #commonlisp
perrierjouet has quit [Quit: WeeChat 3.6]
razetime has joined #commonlisp
perrierjouet has joined #commonlisp
random-nick has joined #commonlisp
cosimone` has joined #commonlisp
<phoe>
oh, good, it's my error instead
rodicm has joined #commonlisp
rodicm has quit [Client Quit]
<_death>
one problem with echo-stream is that unread-char on it may have effect on the echo stream, but not the output stream
lisp123 has quit [Remote host closed the connection]
thuna` has quit [Ping timeout: 250 seconds]
Noisytoot_ is now known as Noisytoot
pranavats has left #commonlisp [Error from remote client]
pranavats has joined #commonlisp
aartaka has joined #commonlisp
waleee has joined #commonlisp
dra has joined #commonlisp
tevo has quit [Ping timeout: 244 seconds]
causal has quit [Quit: WeeChat 3.6]
Noisytoot has quit [Excess Flood]
Noisytoot has joined #commonlisp
<jcowan>
hayley: I was asked to take a test this week in order to be considered for employment, involving writing part of a program. The program was supposed to allow the user to create a (simulated0 squad of toy soldiers selected from a box. One of the requirements read something like "The soldiers must be ai where i < 0 < N". I immediately wrote a comment into the test saying that this requirement was nonsense, saved it, and moved on.
aartaka has quit [Ping timeout: 265 seconds]
<phoe>
you mean negative integers?
aartaka has joined #commonlisp
rurtty has quit [Quit: Leaving]
<hayley>
@jcowan: I had an question in that assignment which mentioned how an array of indices should look (in C). The array was nonsense to me, until I sat down with a friend to talk about it, and we realised the indices started at 1.
<jcowan>
smh
<hayley>
The assignment also mentioned having to implement a parallel sorting algorithm, which apparently could not read the strings it was sorting. I decided to ignore that requirement.
<jcowan>
You had more patience than I would have had
<jcowan>
(admittedly my patience has been sorely :-) tried in the last 2 weeks due to an ongoing toothache)
<hayley>
The assignment was worth a lot of my final grade, so I kinda had to be patient. But the student union did get to hear from me about the lack of a rubric, too, and my other colleagues did hear about my failure to parse much of the spec.
<hayley>
My instructor even gave up trying to make sense of the assignment! But apparently we are getting a lot of slack, due to the number of complaints.
srji has quit [Quit: leaving]
<hayley>
Sorry about the toothache, and best of luck with employment.
<contrapunctus>
hayley: * even my instructor (assuming the notable thing is the instructor giving up, rather than the giving up itself)
<hayley>
Thanks.
<hayley>
jcowan: Does remind me, I've frequently heard the justification that "one will get self-contradictory specifications in the real world". You seem to be in the real world, so how do you manage those?
<jcowan>
Ask questions!
<jackdaniel>
toss a coin and pick the more interesting requirement ,)
<hayley>
Fair enough. Then if the answers cause more head scratching?
<jcowan>
When I interview people for programming jobs, I ask them a question which literally cannot be solved if they jump to conclusions, but if they ask "What is the range of possible inputs?" they can work it out.
<jcowan>
I specify that the input is a stream of integers and they are to write a procedure to be called on each integer and return the median of the integers seen so far.
<jcowan>
It also has to run in O(1) time and space.
<_death>
I implemented some paper this week, which had the theory right but the examples wrong.. so I could not reproduce the results and that inserts doubt into my understanding and the code.. then you need to go through multiple times and come up with your own examples
<jcowan>
mmm, I would never be able to catch that with my concrete-operational brain
<jackdaniel>
jcowan: so what is the range of possible inputs? ;>
<jcowan>
Let us say 0 to 32767.
<semz>
jackdaniel: You were playing around with ECL+Emscripten a while back, right? Would you say it is usable yet?
<jackdaniel>
semz: no; not because it requires much work, but rather because I'm lazy
<hayley>
Well, if the domain is bounded, can one compute a histogram of seen values, which would be O(1) space with regards to input length?
<semz>
heh aren't we all
<jcowan>
One of the three virtues of a goodo programmer
<jcowan>
s/goodo/good
<phoe>
jcowan: so we have a a stream of ub15s... the naïve version would be to memorize all the inputs so far and scan the middle, which would give us O(logn) time and O(n) space
<jackdaniel>
imo lazy people are just lazy, nothing to do with virtues; but oh well
<jcowan>
phoe: good so far, how can we get that precious O(1) time and space, though?
<jackdaniel>
jcowan: and how many integers are expected to be in the stream?
<phoe>
another would be more or less what hayley wrote, keep a bucket for each value and
<phoe>
and increase it by 1 every time a new one appears
<jcowan>
Well, say, up to 2^63-1
<jackdaniel>
well, I was hoping for "one"
<hayley>
Then there is the problem of keeping some kind of "index" into the histogram, which points either to the median value, or to the middle - dammit.
<phoe>
that would give us O(1) space
<jcowan>
A histogram, right, and that should lead you to the O(1) time solution as well
<phoe>
wrt time, you could say that on each pass of the algorithm you go through the whole histogram - you go through all 32768 values, which is O(1) in theory
<phoe>
even though I'd nitpick that you could optimize this further depending on the size of the integers that come in
<hayley>
The index can be updated after receiving another integer in O(1) time, but this message is too small to contain the algorithm.
<jcowan>
Correct! And what is the best data structure to represent this histogram.
<jcowan>
?
<hayley>
The trivial O(1) access option would be an array, with the same size as the input domain. But that is infeasible for "up to 2^63 - 1" now.
<jcowan>
hayley: You have confused the number of inputs with the size of the inputs.
aartaka has quit [Ping timeout: 260 seconds]
<jeosol>
jcowan: I would be using a heap data structure for that. Two heaps in fact.
<jcowan>
That requires O(n) space, alas.
<jeosol>
I thought you meant time
<jcowan>
Time and space, both
<jeosol>
I see.
<phoe>
an array would be a O(1) solution
<phoe>
constant time access, constant space because we need to store a total of 32768 * 2^64 bits of data
<jeosol>
I guess others have asked, at the integers bounded? that could be taken advantaged of
<hayley>
Oh, 2^63 - 1 was for a different question.
<jackdaniel>
median*
<jcowan>
phoe: No no, 32768 * 64 bits, not 2^64 bits.
<phoe>
oeeufhskldfjsdf, yes, apologies
<pjb>
finite universe, O(1).
<phoe>
each integer takes 64 bits
<jcowan>
If you also keep track of k, the number of integers seen so far, you can stop scanning the array when you have gotten to k/2.
<hayley>
Another option perhaps is a trie of number -> count, but 32k × 64 bits should at least fit in L2, so I'm not that bothered about constant factors.
<jeosol>
jcowan: do you care about tracking only the median and no other statistics about previously seen numbers?
<jcowan>
Well, adding the mean and (biased) variance and standard deviation would be trivial. What do you have in mind?
<hayley>
Anything - loop fusion FTW
<jcowan>
s/mean/various means
<jeosol>
Oh, not other statistics, like those. I mean say, you removed some numbers or depending what other operation, say last K median, etc, where K is not the full dataset
<jeosol>
but I think a clarification of the expections, range, features required, is need to be able to give a good solution, ...
<jcowan>
jeosol: Well, that's part of the point. A good engineer, given a vague specification that omits those things, should *ask*. People almost always try to find an algorithm that works on arbitrary integers, which (I conjecture) does not exist.
<jcowan>
pjb: correct: finite word = O(1)
<jcowan>
and after all, we implement things on finite computers.
<hayley>
I guess I was wondering what to do, when the answer-giver is still unreliable. As others in my class found more confusing answers to their questions, and couldn't tell which answers were considered canonical.
<jeosol>
jcowan: I see what you mean. I caught this topic midway, but is this in the context of an interview setting. In that case, a candidate is expected to ask clarifying questions and discussion different approaches from brute force, see possible tradeoffs of space and time and arrive at something optimal
<jcowan>
Right. But I contend that that is *also* what you do in the Real World.
<jeosol>
jcowan, of course, I don't mean to say only in interview setting
* jcowan
nods
<jcowan>
hayley: In that case, I guess you escalate to someone higher up
<jeosol>
more so in the real world for a feature to be implemented otherwise, you get technical debt for doing the wrong thing. Definitely more so in the real world
<hayley>
(From memory the solution to that mess was that any not-self-contradictory set of answers could be chosen for one's interpretation of the assignment.)
<jcowan>
Wow. You have to work *hard* to be that wrong.
<jcowan>
(the teacher, that is)
<hayley>
My favourite such answer was that, with no indication otherwise, the instructions for one question were "just a suggestion". So I should be able to submit nothing, if everything is the same, and something was a suggestion.
<jeosol>
on a related topic, I was add to do some code monkey interviews a few years back, I wanted to use CL, as I was told I could use anything, it wasn't on the list, if I recall. The platform was coderpad (if memory serves me right).
srji has joined #commonlisp
<hayley>
Yes, it was fun to ponder about.
<jeosol>
I am familiar with LC, and I think for those interested, it should be possible to implement something similar for CL and related languages but given people's aversion to parenthesis, hmmm, I don't know
<jcowan>
What is LC? (asking a clarifying question)
<hayley>
I had quipped about the next assignment, which apparently could be done in "any language", that it being a group assignment meant it could not be done in any language.
<hayley>
Though, the assignment is about poking around some open source codebase and I am proposing to my group to poke about SBCL, so what can I really quip about?
<jcowan>
Well, presumably that meant any language the group decides on, just as, if you had been doing it yourself, it would have been any language you decided on. You would hardly be likely to write it in FACT if (as I suppose) you don't know anything about FACT.
<hayley>
Sure.
let-over-lambda has quit [Changing host]
let-over-lambda has joined #commonlisp
<jcowan>
FACT (I add, being firmly in the grip of Geek Answer Syndrome) is sort of the road not taken in Cobol development. It was one of the options proposed as the base language on which Cobol would be built, but (thanks chiefly to Grace Hopper) it was rejected in favor of her FLOW-MATIC language.
<hayley>
I would pick different languages than the group, still; and it would of course be a bad move for the group to use a language they don't know well. So there were factors other than my imagination at play.
thuna` has joined #commonlisp
<hayley>
Oh, and the instructors had to be able to understand the language. Which I should ask about, though for the former "C or C++" assignment they admitted they don't know much C++. (Before I knew what the assignment was, I was thinking of using it as an excuse to learn OCaml.)
<hayley>
Enough storytelling for tonight; I'm off to bed. Thanks for the chat.
xlarsx has joined #commonlisp
<jeosol>
hayley: good night in the down and under. Catch you later
<jeosol>
jcowan: pardon, LC is Leetcode, a platform SWE and other related disciplines use to practice and prepare for coding interviews
<jeosol>
The platform has several programming languages and I had thought, many moons ago, nothing wrong with using LC, we'd just create some standard mathematical algorithm libraries, e.g., a default sort library, etc. But CL coding is not as in the other languages, Python, C/C++, Java, being the more popular languages on the platform.
XZDX has joined #commonlisp
pjb has quit [Read error: Connection reset by peer]
dra has quit [Ping timeout: 248 seconds]
rgherdt has quit [Remote host closed the connection]
rgherdt_ has joined #commonlisp
dilated_dinosaur has quit [Ping timeout: 268 seconds]
pranavats has left #commonlisp [Error from remote client]
karlosz has quit [Remote host closed the connection]
pranavats has joined #commonlisp
attila_lendvai has joined #commonlisp
tyson2 has quit [Remote host closed the connection]
attila_lendvai has quit [Ping timeout: 268 seconds]
XZDX1 has joined #commonlisp
XZDX has quit [Ping timeout: 244 seconds]
robin has quit [Ping timeout: 244 seconds]
dilated_dinosaur has joined #commonlisp
xlarsx has quit [Remote host closed the connection]
mathrick has quit [Read error: Connection reset by peer]
mathrick has joined #commonlisp
McParen has joined #commonlisp
verisimilitude has joined #commonlisp
igemnace has quit [Remote host closed the connection]
aartaka has joined #commonlisp
zyni-moe has joined #commonlisp
zyni-moe has quit [Quit: died]
karlosz has joined #commonlisp
tyson2 has joined #commonlisp
thuna` has quit [Remote host closed the connection]
aartaka has quit [Ping timeout: 260 seconds]
aartaka has joined #commonlisp
jeffrey has quit [Ping timeout: 265 seconds]
igemnace has joined #commonlisp
frgo has quit [Ping timeout: 268 seconds]
pjb has joined #commonlisp
dra has joined #commonlisp
triffid has quit [Remote host closed the connection]
triffid has joined #commonlisp
dra has quit [Ping timeout: 268 seconds]
xlarsx has joined #commonlisp
<Josh_2>
Good Morning
<Josh_2>
:sunglasses
<Josh_2>
:sob:
<phoe>
good evening
<phoe>
B)
<Josh_2>
:sunglasses:
<Josh_2>
Anyone use Series in production code?
aartaka has quit [Ping timeout: 260 seconds]
aartaka has joined #commonlisp
xlarsx has quit [Read error: Connection reset by peer]
pranavats has left #commonlisp [Disconnected: Replaced by new connection]
pranavats has joined #commonlisp
Lord_of_Life has quit [Ping timeout: 265 seconds]
Lord_of_Life has joined #commonlisp
<jackdaniel>
since the production is all about conveyor belts, series make perfect sense
* jackdaniel
gasps
tyson2 has quit [Remote host closed the connection]
aartaka has quit [Ping timeout: 244 seconds]
McParen has left #commonlisp [#commonlisp]
aartaka has joined #commonlisp
xlarsx has joined #commonlisp
xlarsx has quit [Ping timeout: 260 seconds]
aartaka has quit [Ping timeout: 260 seconds]
aartaka has joined #commonlisp
xlarsx has joined #commonlisp
xlarsx has quit [Ping timeout: 244 seconds]
yottabyte has quit [Quit: Connection closed for inactivity]
aartaka has quit [Ping timeout: 244 seconds]
Guest2902 has quit [Quit: WeeChat 3.6]
igemnace has quit [Remote host closed the connection]
xlarsx has joined #commonlisp
tyson2 has joined #commonlisp
xlarsx has quit [Ping timeout: 265 seconds]
xlarsx has joined #commonlisp
psf has quit [Read error: Connection reset by peer]
psf has joined #commonlisp
psf has quit [Read error: Connection reset by peer]
psf has joined #commonlisp
psf has quit [Read error: Connection reset by peer]
Haematophage has quit [Ping timeout: 265 seconds]
Colere has joined #commonlisp
Furor has joined #commonlisp
psf has joined #commonlisp
Colere has quit [Ping timeout: 252 seconds]
psf has quit [Read error: Connection reset by peer]
dra has joined #commonlisp
psf has joined #commonlisp
Oladon has joined #commonlisp
cage has quit [Quit: rcirc on GNU Emacs 27.1]
zyni-moe has joined #commonlisp
antoszka has quit [Quit: WeeChat 3.5]
psf has quit [Read error: Connection reset by peer]
antoszka_ has joined #commonlisp
zyni-moe has quit [Quit: died]
antoszka_ is now known as antoszka
psf has joined #commonlisp
psf has quit [Read error: Connection reset by peer]
chipxxx has joined #commonlisp
dilated_dinosaur has quit [Ping timeout: 248 seconds]
psf has joined #commonlisp
psf has quit [Read error: Connection reset by peer]
frgo has joined #commonlisp
psf has joined #commonlisp
psf has quit [Read error: Connection reset by peer]
xlarsx has quit [Remote host closed the connection]
psf has joined #commonlisp
jmdaemon has joined #commonlisp
shka has quit [Ping timeout: 252 seconds]
psf has quit [Read error: Connection reset by peer]
random-nick has quit [Ping timeout: 252 seconds]
psf has joined #commonlisp
psf has quit [Read error: Connection reset by peer]