freenode/lisp - IRC Chatlog
Search
8:02:57
pjb
seok: accessing the nth element of a list is an operation that takes O(n) memory accesses (and increment and tests). Accessing the nth element of a vector is an operation that takes O(1) memory accesses (and one addition, and one test).
8:03:28
pjb
seok: but notice that accessing the 1st element takes about the same time; when n=1, O(n) = O(1) !
8:04:36
pjb
seok: on the other hand, extending the size of a vector is an operation that takes O(n) (with n=(length vector)), since we have to copy all the old elements of the vector to the new bigger vector. while extending the size of a list if done at the head, is an operation that takes O(1), since we only need to add a single cons cell.
8:05:03
pjb
ecraven: indeed. O(n) is meaningful only when you consider big and bigger data structures.
8:05:22
pjb
seok: so if you only have a handful of elements, it doesn't matter whether you use a vector or a list.
8:06:43
pjb
seok: now, adding elements in vectors can be done in O(1), using vectors with fill-pointers, at the cost of pre-allocating the maximum number of elements you may have to store.
8:07:34
seok
I am specifically looking to store game object data like coordinates, velocity and such
8:08:21
pjb
seok: there's also the case where you need to insert new elements in the middle of the sequence. Here, list can be O(1) if you already have a reference to the cell in the middle of the list, while with a vector you will have to displace the remaining elements, so it'll be O(n).
8:08:28
seok
Probably would reserve empty indices to add or remove object to avoid changing vector length
8:09:48
pjb
Well, there are sorting algorithm that work on list directly, but AFAIK, for big sequences, if will always be faster to convert to vector, soft the vector, and store back the sorted elements in the list. So I would guess that all sane implementation do that. (but I suspect one or two use a list sorting algorithm).
8:12:31
pjb
Also, I would expect to have to access objects geographically. There are more sophisticated data structures that would help there. For example quad-trees. (or octo-trees in the case of 3D).
8:12:55
pjb
Of course, you can implement quad-trees using vectors (I did that once for a big tree, that was mmap'ed from disk).
8:18:53
shka__
having said all that, it is usually good idea to start with vectors is you simply need a sequence of elements with random access
8:23:01
pjb
seok: that said, if you multiply the size of the vector by a constant > 1 (preferably closer to or bigger than 2) when you need more space, then inserting elements remain O(n) instead of O(n²). http://www.cs.cornell.edu/courses/cs3110/2011fa/supplemental/lec20-amortized/amortized.htm
8:24:38
aeth
If it's for a game, though, it's perfectly fine to have some fixed upper limit in size. Most do somewhere.
8:25:06
aeth
And once you have a limit might as well allocate it all because RAM's cheap and it's probably tiny compared to the textures.
8:29:23
pjb
Definitely. For games other considerations enter the scene. For example, pre-allocating arrays lighten the load for the garbage collector, which may be a good thing for real-time games.
8:46:23
pjb
But we're talking into the million elements. A vector of 1 million fixnum takes 8 MB (64-bit); a list of 1 million fixnum takes 16 MB.
9:02:07
phoe
it's a copypaste from pgloader - my biggest question is if I got licensing right on that one
9:02:13
shka__
for now, i just wanted to point out that alexandria already has some of the functions you implemented
9:02:51
shka__
and i think it is wise to use alexandria tools whenever possible instead of defining your own
9:03:24
phoe
shka__: file a pgloader issue then, https://github.com/dimitri/pgloader/blob/master/pgloader.asd#L19
9:10:16
aeth
pjb: Two additional issues other than just the memory size. (1) the list might not be together in memory and (2) if the large vector has an element-type that's not T it afaik greatly simplifies the GC process
9:15:41
aeth
shka__: the list won't just be slower... I think (hope? I don't see why not) that the GC scanning the vector would be O(1) if the vector can only hold something like single-float or (unsigned-byte 8)
9:16:19
aeth
Use a 2D array instead of a vector-of-vectors and you could see some major GC improvements if that's the case, assuming there's an element-type that works.
9:26:47
phoe
as in (let ((solution (make-generational-gc))) (declare (considerable-extent solution)) ...)?
9:43:21
dimpase_
it seems that the only way to use ASDF if the compiler cache and the package you build is by doing (asdf:disable-output-translations)
9:47:15
jackdaniel
i.e :move-here "/opt/foo/" where /opt/foo is on /dev/sda1 and /home/dimpase/.cache/ is on /dev/sda2
9:48:00
jackdaniel
that is a copy operation, so it is not very suprising you can't "move" there (however inconvenient)
10:23:45
dimpase_
Unable to rename file #P"/home/dima/.cache/common-lisp/ecl-16.1.2-unknown-linux-x64/mnt/opt/Sage/sage-dev/local/var/tmp/sage/build/kenzo-1.1.7-r1/src/kenzo--all-systems.fasb" to #P"/mnt/opt/Sage/sage-dev/local/var/tmp/sage/build/kenzo-1.1.7-r1/src/kenzo--all-systems.fasb".
10:36:12
jackdaniel
well, not really. I'm ECL maintainer so I just happen to know these parts of asdf and ecl.
13:07:38
cryptopsy
how to make a function that takes a line and returns a local variable which is a number of the occurance a character occurs in that line?
13:08:01
cryptopsy
seems wasteful for it to run recursive, so i opted to use a (let ((indent 0)) ...
13:17:05
cryptopsy
i am trying to call the function that returns the line in while line do but i am not sucessfull
13:20:34
cryptopsy
i think i might be in the wrong dir and the file it is supposed to open is not there
13:21:55
cryptopsy
i used to have a zone of dead pixels where i am keeping the sbcl window, but even after changing the screen my mind is still recognizing that zone as dead pixels and doesn't immediatly focus on the text in that corner
13:23:42
cryptopsy
i am a gentoo user, i have to set app-editors/vim python_single_target_python2_7 , this seems weird to me because it is set in make.conf
13:25:28
grewal
From the turorial, "You will also need a Python enabled Vim, and the same Python version installed that is Vim compiled against."
13:26:46
cryptopsy
perhaps because it is built with PYTHON_SINGLE_TARGETS python3_6 but slimv wants python2_7 on itself
13:28:21
grewal
vlime doesn't require python. But if you want paredit, you'll have to install that separately.
13:31:55
cryptopsy
it has been my dream this last decade to do that and i only have 3 days it until i start a career that won't permit me to have this hobby anymore
13:36:19
cryptopsy
what is the data-type of lines from (loop for line= (read-line stream nil) , i think it is a string?
13:44:35
gilberth
cryptopsy: What should the function do anyway? Counting the leading #\Space characters?
14:00:55
cryptopsy
i am aware there are many ways to do it, i am doing this as a learning exercise with primitives i understand
14:20:51
cryptopsy
i am attempting to write this function that takes a string but returns the value of a local variable
14:22:06
cryptopsy
would this be better to have beeen written as a recursive function considering the indents are almost always less than 20 ?
14:39:00
jurov
Can anyone please enlighten me why in my recursive function these two forms behave differently: (concatenate 'list '( [ ) (recurse x) '( ] ) ) and `( [ ,@(recurse x) ] )
14:41:40
Bike
cryptopsy: they may be garbage collected at any point at which they are no longer reachable.
14:43:43
cryptopsy
or are all the exercises virtually the same but in the lisp lang instead of scheme
14:44:21
cryptopsy
Bike: if the function ends, and is never used again, does it still have allocated that local var somewhere
14:49:06
sjl_
I think it's pretty uncommon for a garbage collected language to define when garbage collection of local variables occurs.
14:49:14
cryptopsy
so i am reading here: """ While Garbage Collection (GC) was one of the major innovations of Lisp, there have been many attempts to get rid of it in one way or another. """
14:50:36
sjl_
Tell Bike you have a local variable pointing at a 10gb array and you want to know when it's safe to open Slack again without the OOM killer killing your program or something, if you want to get an answer.
14:50:52
beach
cryptopsy: No, it is not interesting. You really don't want to know. The system will run the garbage collector when it sees fit.
14:51:10
Bike
Sometimes, for optimization reasons, it is important to care about what the garbage collector is doing.
14:51:28
beach
cryptopsy: Manual memory management is one of the main sources of bugs. We are lucky not to have to do that.
14:53:47
sjl_
Out of curiosity: does the spec even require garbage collection? Could a CL implementation just allocate until OOM and still satisfy the spec?
14:54:22
cryptopsy
does clasp compile to llvm ir directly or does it produce intermediate C or C++ ?
14:57:49
sjl_
https://groups.google.com/forum/message/raw?msg=comp.lang.ada/E9bNCvDQ12k/1tezW24ZxdAJ
15:02:38
grewal
cryptopsy: Some lisp implementations expose parts of the garbage collector. See, e.g. http://www.sbcl.org/manual/#Garbage-Collection
15:28:01
cryptopsy
beach: i saw a presentation a chemist made where he implemented his own lisp to solve molecular problems
15:35:32
verisimilitude
An implementation is supposed to signal STORAGE-CONDITION in cases such as memory exhuastion, sjl.
15:44:29
phoe
"In general, the entire question of how storage allocation is done is implementation-dependent, and so any operation might signal storage-condition at any time."
16:05:59
pjb
cryptopsy: Movitz https://common-lisp.net/project/movitz/movitz.html is a CL implementation that runs currently on Muerte, a x86 run-time environment that does not provide a garbage collector. (Movitz is designed to implement operating systems).
16:42:00
beach
housel: There are rumors that he wants to create a new version. And now there is also Mezzano.
16:54:15
beach
cryptopsy: Common Lisp is defined so that the READ function takes a sequence of characters and produces a Common Lisp data structure, which is then further processed by a compiler or an interpreter.
16:55:12
beach
Some people call it that. I don't. It's a Common Lisp data structure made up of lists and atoms.
16:55:42
beach
cryptopsy: Because, as I said, the language is defined to have a standard READ function.
16:56:22
cryptopsy
well it can read the terms and create the linked structure without translating to tokens and then build an AST from a tokenized string
16:58:39
beach
cryptopsy: I am not sure whether you are asking "Why does this particular implementation work like that?", or "Why was the language defined that way?".
17:21:14
verisimilitude
By having READ available by itself, you can easily, say, read in data that has previously been written, cryptopsy. With Common Lisp, you can delay defining a format for serialized data beyond READ and WRITE indefinitely.
17:30:17
phoe
sure, but there is a level when you are somewhat competent with its concepts and workings
17:30:39
dlowe
cryptopsy: okay. We have many, many people who pop in and want to know, abstractly, all about lisp without ever wanting to write a line of code
17:47:12
francogrex
(r% "glm" :formula "outcome ~ predictor" :family "poisson" :offset (r% "as.matrix" (r% "log" (r% "subset" sub :select "doses"))) :data sub)
17:51:39
cryptopsy
how do i disable the header when sbcl runs " This is SBCL 1.5.0, an implementation of ANSI Common Lisp. ...."
17:53:01
francogrex
and it's not really correct what you say dlowe because: (defparameter x (values))
17:54:02
francogrex
while (defparameter xx (r% "glm" :formula "outcome ~ predictor" :family "poisson" :offset (r% "as.matrix" (r% "log" (r% "subset" sub :select "doses"))) :data sub))
17:55:07
cryptopsy
how do i print lines with write when doing (loop for line = (read-line stream nil) while line do ( ...
17:58:36
dlowe
francogrex: the only thing I can think of is that r% is generating a condition that's being silently swallowed by the repl
17:59:50
sjl_
2019-01-11 12:44:23 <scymtym> if the implementation's REPL establishes an ABORT restart, the behavior could be caused by code like (multiple-value-list (handler-bind ((error #'abort)) (/ 2 0)))
18:02:57
francogrex
like the easy one that does not require changing the code? I guess it would be to
18:03:08
sjl_
Depends on what you're actually trying to do. Are you trying to detect when this happens?
18:08:14
dlowe
you can also (declaim (sb-ext:muffle-conditions style-warning)) at the top of the file
18:08:16
sjl_
Ideally you'd fix the code to not emit warnings. To hide the warnings, use the solution found in the first google result for "sbcl disable warnings"
18:09:09
dlowe
declarations about variables occur at the beginning of the body of the variable's scope
18:13:44
cryptopsy
should i use *standard-input* or *terminal-io* nil EOF for runnning my lisp program with a parameter which is the filename it is supposed to read
18:15:31
pjb
*standard-input* is for batch input. *query-io* is for interactive I/O. *terminal-io* is to communicate with the operator (and it cannot be rebound).
18:16:18
pjb
If you open a file you can rebind *standard-input*: (with-open-file (*standard-input* pathname) (read))
18:17:16
cryptopsy
i can't get *standard-input* to work ,, this was my usage #sbcl --noinform --disable-debugger --load test.lisp tests/alphabet.x
18:20:13
pjb
sbcl --noinform --no-userinit --disable-debugger --eval '(progn (print sb-ext:*posix-argv*) (terpri) (finish-output) (sb-ext:quit))' -- tests/alphabet.x
18:20:46
pjb
sbcl --noinform --no-userinit --disable-debugger --eval '(progn (print sb-ext:*posix-argv*) (finish-output) (sb-ext:quit))' tests/alphabet.x
18:25:38
pjb
cryptopsy: lisp is easy to understand: you look at the first word in the parentheses, and look it up.
18:26:01
pjb
and then you repeat with the sub expressions that are evaluated, according to what you read in the specification.
18:26:51
pjb
cryptopsy: you can copy and paste the irc buffer, and take your time to read and study it. Somebody will still be there when you come back, in 1 hour, 1 day, 1 month or 1 year.
18:29:31
cryptopsy
the practice is, when you have 50 tabs open, u read the first few lines, and if it doesnt answer, you go to the next
18:29:44
pjb
cryptopsy: again, I've shown you how to do it. Why you keep writing wrong forms? If you don't want to learn, don't come here.
18:32:12
pjb
dlowe: when people say they don't want to learn, and show that they don't learn anything, nope.
18:33:23
pjb
I give my time for free, if it's to throw it to the trash, it's VERY RUDE. So fuck off!
18:33:44
cryptopsy
""The only required argument to OPEN is the name of the file to read."" interesting, just like all the other 1000 lines irrelevant to what i have in my program
18:33:45
grewal
cryptopsy: It sounds like you need a small break to process everything. Learning a language takes time. Copy-and-pasting and brute-forcing can only get you so far
18:35:14
cryptopsy
so i'm looking at this huge ammount of data (pictured her https://i.imgur.com/VCJsrVN.png) , and then i'm looking at my line, pictured here https://i.imgur.com/VCJsrVN.png
18:36:16
pjb
cryptopsy: this is why you should read a tutorial from start to end. Tutorials are short and pedagogical. You can read and LEARN 50 pages in a week.
18:36:17
buffergn0me
cryptopsy: It looks like you might be confusing streams/file descriptors with file names
18:37:32
cryptopsy
(now im looking at my imgur script which i replaced earlier, wondering why it didnt produce a link ..)
18:38:40
dlowe
CL is a fairly hard language to just dive into without going step-by-step through a learning book
18:39:06
dlowe
My learning book was Common Lisp: the Language, which I don't recommend but it was there at the time.
18:40:08
cryptopsy
*standard-input* isnt even on http://www.gigamonkeys.com/book/files-and-file-io.html
18:42:05
buffergn0me
cryptopsy: Well, are you trying to read from stdin or open a file? Totally different things
18:42:23
dtw
cryptopsy: You seem to think that you need *standard-input* stream. Do you know what it is?
18:47:05
aeth
dlowe: Manual freeing gets you a lot of unwind-protect... you can already see this in CFFI code where you control the allocations
18:48:48
buffergn0me
cryptopsy: I think it would help if you read a Unix introductory programming tutorial that covers file and IO system calls. The CL tutorials cover CL specific stuff and assume you know about file descriptors and the filesystem
18:50:43
buffergn0me
cryptopsy: Something like Stones and Matthew's Beginning Linux Programming explains files, file descriptors, pipes, and IO redirection, and you can use it as a reference
18:58:33
cryptopsy
when i decide how to handle command line parameters in a case i will deal with that case
18:58:53
cryptopsy
i was hoping to have solved this in 30 seconds while taking my mind off a recursive function
19:05:33
pjb
Well, only once you realize those 40 lines can be written in 10 if you use CL instead of re-implemeting functions like count or find…
19:12:10
polezaivsani
for asdf's defsystem, the manual states that :depends-on can have a list of component names. does it mean a system can depend not just on other systems, but also file components?
19:14:32
polezaivsani
dlowe: how does it help defining inter file deps when it's being set within a system definition? n.b. i'm totally new around here
19:16:55
pjb
(defsystem :foo :depends-on ("other-system-1" "other-system-2") :component ((:file "foo1") (:file "foo2" :depends-on ("foo1")))
19:18:35
polezaivsani
that's clear for system's components, but can e.g. "other-system-1" or "other-system-2" be infact a non system component?
19:20:46
polezaivsani
the hole reason, i'm asking it is i stumbled upon a system definition like (defsystem foo :depends-on ("split-sequence")), and as far i could figure, split-sequence isn't a system anylonger. Could it be that it's just an old definition from time where split-sequence was a system by itself?
19:23:18
polezaivsani
oh, so it's not being part of cl-utilities, it's just being rexported from it, right?!
19:24:36
phoe
(and got a decent overhaul in the process, https://github.com/sharplispers/split-sequence/pull/13)
19:25:06
aeth
Tangentially related, but splitting sequences is probably the wrong way to deal with most things in CL. For arrays you can just work with indices, for lists you should think about if you e.g. really want to turn '(a b c d) into '(a b) and '(c d) or if you just want '(c d) which is far more efficient (or similar list tricks).
19:25:41
polezaivsani
oh, i see. i happen to get the wrong idea from glossing over a quick cliki search
19:25:46
phoe
polezaivsani: also, from what I see, most of cl-utilities made its way into alexandria
19:27:00
_death
though it was explicitly ruled out at the time, I think it'd be nice by now to put split-sequence into alexandria ;)
19:28:00
aeth
phoe: You can often/usually just subseq as the final (in the program) step and save a bunch of intermediate splits
19:28:11
_death
phoe: the idea was explicitly rejected when alexandria was created.. I know it will be rejection still
19:29:09
polezaivsani
nice, from a couple hour long acquaintance with cl-utilities i didn't manage to like the name :) thanks for the tips!
19:30:53
_death
personally I use split-sequence a lot, and have great distaste for ppcre or other regex packages (unless they're part of the UI.. then they're ok)
19:33:50
dlowe
if you're doing string processing, you have already lost the clean data model. Might as well regex it up
19:34:37
pjb
aeth: this is why there's com.informatimago.common-lisp.cesarum.array:positions-of-subsequence
19:35:07
_death
dlowe: not my experience.. I have used regexps for some quick hacks, but usually there's no need
19:36:37
aeth
pjb: Right (at least about the principle, never used the library), you work with position indices until the final step and then you only do the final subseq(s). This saves a lot of intermediate subseqs since you only need to subseq the strings
19:37:22
aeth
If you're parsing some data format it'll probably be like 95% read-integer or direct string matches (like "true" to t) and 5% actually saving some of the string data
19:37:33
pjb
Compar: (values (split-sequence #\SPACE "Hello World, How do you do?") (positions-of-subsequence " " "Hello World, How do you do?")) #| --> ("Hello" "World," "How" "do" "you" "do?") ; ((5 . 6) (12 . 13) (16 . 17) (19 . 20) (23 . 24)) |#
19:38:11
pjb
aeth: however, creating short substring is usually very efficient, even compared to consing and working on subseqs.
19:38:29
_death
usually such string processing happens at the edge of the system, you receive some input, parse it into an internal representation, and then the real processing happens
19:38:39
aeth
_death: Well, it's more about how CL was designed to handle vectors (including strings)... which is with all relevant built-in functions (and all well-written third-party) functions including start/end indices
19:39:20
aeth
_death: of course you can use a surpirsingly heavy library to use your own model.... turing complete and all
19:40:00
cryptopsy
less interested in print becaues i have read it is outdated but it was a desperate attempt
19:41:13
pjb
write is a low level function that use a bunch of global variable parameters as defaults. princ, prin1 and print just call write, with specific values for some of those parameters.
19:42:25
_death
aeth: I use start/end as well.. but I wouldn't normally store indices to strings without evidence that it matters
19:42:29
pjb
Yes, this is the first thing all lisp tutorial would have taught you, if you wanted to learn anything.
19:42:44
cryptopsy
must have gotten confused about the syntax from some shitty stackoverflow posts along the way
19:43:18
_death
aeth: I do think it's a good idea to provide start/end functionality when writing string/sequence utilities
19:43:21
pjb
cryptopsy: this is why I gave you this link http://cliki.net/Online+Tutorial and not a shitty stackoverflow link!
19:43:54
_death
aeth: in fact I remember an old presentation by tcr when he proposed some nice operators to help do just that
19:44:45
pjb
cryptopsy: the source of lisp code is a lisp object, a symbolic expression (s-expr), which is an atom or a list of s-exprs.
19:45:34
phoe
cryptopsy: yep, some people don't like it, since it isn't very "lispy". As in, it lacks parens.
19:46:06
_death
cryptopsy: maybe try to avoid the long form of loop for now.. instead you can use DO.. I think newbies should go through no-loop phase at some point
19:46:35
cryptopsy
what should i use to inspect my terms for debugging? i think that would be useful
19:46:56
phoe
#'MACRO-FUNCTION and #'SPECIAL-OPERATOR-P will return NIL if passed a symbol that isn't bound to a macro or a special operator.
19:47:02
aeth
_death: The only time I wouldn't use start/end on strings, personally, is if something was mutating them somewhere along the line. Even there, it'd probably try to find some way to make it work. Of course, this is assuming elaborate processing. At the end, SUBSEQ makes sense if it is supposed to be stored as a string, of course.
19:47:48
phoe
cryptopsy: you really need to do some basic reading on Lisp. It's hard to help you if you don't know basic concepts such as quoting.
19:47:53
aeth
_death: If it's just a CSV into an object holding strings or something similarly simple, sure, splitting makes sense
19:48:05
cryptopsy
it was a last minute decision to use lisp, i came here from watching a scheme presentation
19:48:23
phoe
cryptopsy: well, you don't walk into a new language and start using it straight away without learning it first.
19:49:22
aeth
cryptopsy: Usually people use IDEs, which expose the API of the function/macro. e.g. in a properly configured Emacs+SLIME, it will show up in the mini-buffer at the bottom. It's usually extremely obvious by the API if it's going to be a macro because it will have stuff like (foobar (x y) (&rest foo) &body body) that are impossible in function APIs
19:49:58
aeth
cryptopsy: of course, relying on the API isn't perfect because people could be e.g. using macros instead of inline functions (justifiably or not)