freenode/lisp - IRC Chatlog
Search
4:29:58
pjb
(loop for voo in '(k1 k2 k3) collect (case voo ((k1 k2) '12) (k3 '3))) #| --> (12 12 3) |#
4:31:06
pjb
cryptopsy: actually I would advise to always wrap the keys in the case clauses in parentheses, even when there is a single one (case voo ((k1 k2) '12) ((k3) '3) ((nil) '0)) for the case where you want to test for nil. Because (case nil (nil 'nope) ((nil) 'yep)) #| --> yep |#
4:33:56
cryptopsy
can i do 'else' in a case? like, if none of the cases matched, then do that thing keyn
4:34:36
pjb
(case 3 (2 'nope) (otherwise 'yep)) #| --> yep |# (case 3 (2 'nope) (t 'yep)) #| --> yep |#
4:36:01
pjb
it's used usually in cond or the otherwise case: (let ((foo 3)) (cond ((eql foo 2) 'nope) (t 'default))) #| --> default |#
4:36:51
pjb
on the paper, 0 and 1 were used in 1959, but in the first implementation they already switched to symbols, NIL and T.
4:37:21
cryptopsy
i understand that its a binary logic, just not why it would be true rather than nil
4:37:39
pjb
That was long before otherwise was considered as a keyword. otherwise would have taken two word to store the characters, and two words to store the pointers of the list, so it would have be a little costly as a keyword…
4:37:44
cryptopsy
'otherwise' more like it would be a false, as in it is false that there was a match
4:38:15
pjb
Have a look at https://www.reddit.com/r/lisp/comments/4mp4oy/lisp_i_and_lisp_15_manuals_source_code/
4:39:22
pjb
antecedent1 -> consequent1 , antecedent2 -> consequent2 , … , true -> default-consequent
4:41:25
pjb
that's where the CAR and CDR came from, and this processor also had a XEC instruction similat to eval, to execute an instruction stored at the given address.
4:42:06
pjb
cryptopsy: you understand now why the cost of the computer was nothing: it was the cost of the electric and air conditioner installation, and electricity bill.
4:43:17
pjb
The first 7090 installation was in November 1959. In 1960, a typical system sold for $2.9 million (equivalent to $18 million in 2018) or could be rented for $63,500 a month (equivalent to $405,000 in 2016).
4:43:26
cryptopsy
there are surface grinders with 100kw motors, when the factor runs those the power bill goes up by millions of dollars for the month
4:47:05
pjb
The basic memory cycle was 2.18 μs, so basically (/ 2.18e-6) #| --> 458715.62 |# less than half a mega instructions per second at most.
4:47:57
cryptopsy
i made this program to try to count whitespace at the beginning of each line, but it doesnt give any output when running in sbcl (stuck?) https://pastebin.com/TLvrS9NH
4:50:33
pjb
defvar (and all other forms with operator having a name prefixed with "DEF") should only be used as a toplevel form.
4:51:16
pjb
The reason is because its effects cannot be known before the expression is compiled. So the indent variable in your expression cannot be the indent variable defined by defvar.
4:51:49
pjb
Also, defvar and defparameter define special variables. Since they're special you should name them with stars *indent* to show that they're special and so you're careful in their use.
4:52:09
pjb
The specialness of those variable is that all their bindings are dynamic bindings, not lexical binding.
4:52:46
pjb
You can use (count-if (lambda (ch) (find ch #(#\space #\tab))) line) to count the spaces in a line.
4:53:25
pjb
(well, technically there are a few operators that preserve the toplevelness: progn and eval-when amongst others).
4:54:33
cryptopsy
i had put the definition there so that it gets reinitialized to 0 for each line read
4:55:05
pjb
cryptopsy: also, defvar and defparameter define global variables. You should avoid global variables.
5:00:14
pjb
The advantage of using :for, is that it doesn't intern the symbolin the current package, so if you later use-package a package that exports a symbol with the same name as one loop keyword, you won't get a collision.
5:01:10
pjb
Also, the advantage is to use := instead of = := means assignment, while = means equality…
5:08:59
pjb
cryptopsy: https://pastebin.com/NBn740xp you can use position-if-not to find the first non-space character.
5:09:39
pjb
However, it the line is empty, it returns NIL, so you may want to wrap (or (position-if-not …) 0) to fallback to 0 on those lines.
5:23:06
beach
Otherwise, you force people to count parentheses, which Common Lisp programmers never do.
5:23:51
cryptopsy
that's why i put them on their own lines, so i can fold blocks and copy and paste them around
5:26:59
beach
So start by using an editor that understands Common Lisp syntax to indent your code, and remove all the whitespace before closing parentheses.
5:58:30
akater
seok: when it makes sense to process elements of a sequence in parallel, for example. E.g. if you integrate over the elements. But it's not a hard rule. Lists are often convenient.
5:58:41
beach
seok: When you want O(1) access to the elements and you don't need to change the number of elements very often
6:00:33
beach
seok: Use an array (of which a vector is a special case) when you want O(1) access to the elements and you don't need to change the number of elements very often.
6:02:46
verisimilitude
In any case, it can usually be rather easy to switch them around, without changing the code.
6:03:20
verisimilitude
VECTORs and LISTs are both considered SEQUENCEs and many functions simply work on those.
6:13:01
jackdaniel
seok: do not use lists to represent arrays, they are literally given as an example what one shouldn't do in one of Norvig's essays
6:15:44
jackdaniel
(lists are very versatile and are useful for many things, representing arrays is *not* one of them)
6:33:27
verisimilitude
VECTORs are SEQUENCEs and ARRAYs, but other ARRAYs aren't SEQUENCEs, yes, seok.
6:34:04
verisimilitude
Is that the essay about the FORTRAN programmer complaining about how slow Lisp was at the time?
6:34:22
verisimilitude
Yet, this programmer also didn't understand how to use Lisp was part of the issue?
6:37:16
jackdaniel
http://www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf here, it is one of examples of "bad code"
6:39:55
verisimilitude
He also thinks Python is a Lisp, so I'm inclined to be skeptical of his opinions instead of blindly following them.
6:41:11
jackdaniel
either way, I've said what I've wanted to say - advising to represent arrays as lists is harmful
6:41:53
verisimilitude
I can't download this PDF; I'm inclined to believe this server is ignoring Tor connections without rejecting them; I believe I may have had this issue with this server before.
6:46:05
verisimilitude
Oh, I believe I've already been recommended this document and read it before, actually.
7:04:23
aeth
jackdaniel: not just in norvig's essays... it's also in the Worse is Better essay, except with matrices as the example
7:06:08
aeth
As for lists being "convenient"... This is Common Lisp. 90% of what you would want to do with vector-like lists you can also just do with vectors without modifying your code because they're generic for sequences.
7:06:32
jackdaniel
aeth: you are right, thanks for a remainder (I think I would quote it if I had remembered)
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