freenode/#lisp - IRC Chatlog
Search
9:50:44
makomo
say i have a CASE form and i want to run a bit of code before/after the CASE form, depending on whether any of the cases within the CASE was actually hit
9:51:31
makomo
i could do it by adding WHENs before/after the case and then checking for all of the symbols within the case, but this duplicates all of those symbols
9:53:33
ludston
Alternatively, you could yield a non-null value from all of your cases and wrap it in an if or when expression
9:54:38
makomo
plus, it requires me to save that value then somewhere, which means the whole CASE needs to be wrapped within a LET, producing "ugly" indentation
9:54:52
makomo
if i opt for (setf) instead of returning, then i'm again duplicating code within the clauses
9:56:12
ludston
In that case, whether or not this is a better way to do this, I would have the case return a lambda and then wrap the clauses around that
9:56:26
makomo
another style/philosophy issue: where do you draw the line between "i'll just write a macro for it and introduce my own control structure" and "i should probably just let this bit of duplication be, it's not worth the reader's effort to decipher what i meant"
9:58:20
makomo
you want to run some common code, then special code for every clause, then again common code
9:59:17
makomo
i also thought about that, and that's an upcoming optimization, but isn't *that* important
9:59:48
ludston
(let ((c (case "jobbo" ("jobbo" (lambda () (something)))))) (when c (setup) (funcall c) (cleanup)))
10:00:21
makomo
so for example, you can't rely on the check being saved in the after body, if the before body never existed
10:01:23
makomo
in the after body, you can't rely on the check being saved/done already, if the tbefore body never existed**
10:04:19
ludston
makomo: I've found that if you have conditional behaviour, it's often better to delay executing that behaviour by passing it around in higher order functions, since then it is trivial to add logging later
10:05:40
ludston
makomo: Often, conditional behaviour is going to be triggered by some user-input, and the user will input data outside of the range that you predicted, so you will want to anticipate this
10:06:40
ludston
makomo: And by that I mean, anticipate that you will screw up your code, not "try and make sure that all of the inputs are santized"
10:10:23
makomo
i think i see what you mean. so you're referring to the process of actually writing the code, not the runtime behavior of the program
10:12:11
puchacz
by the way, is there "case" with different test instead of default "eql"? or I would have to write a macro (or use one of the libraries)?
10:13:55
loke
puchacz: To your question. You asked if there is such a macro, or if you have to write it yourself. The answer to that question is “yes”.
10:15:20
loke
siraben`: Also, I believe it mentions lispbox or some other similar package which are no longer devloped. You should be looking at Portacle.
10:15:23
makomo
siraben`: skip the part about "lispbox" in the beginning and use something like Portacle instead
10:15:38
siraben`
Fortunately I know how to use Emacs, so I'll find a way to customize my current configuration to work better with CL
10:16:13
loke
makomo: There is a STRING-CASE in Quicklisp which is likely much faster than what you'll be able to write.
10:16:40
makomo
loke: probably, i had no idea though. i expanded it into a COND which uses STRING-EQUAL lol
10:17:07
makomo
loke: what kind of optimization could it do. hash the strings and compare the hashes perhaps?
10:17:16
loke
makomo: smartparens was less efficient last i looked. That said, it also seemed to be easier to learn, so perhaps it's a good idea for beginners.
10:18:30
makomo
ludston: i just learned something :D. i use spacemacs's lisp-state for my sexp operations though
10:18:50
makomo
the keybinds aren't the shortest, `SPC k <something>` and then just `k <something>` once you're in the state
10:18:58
loke
makomo: it finds common prefixes and constructs a tree based on that. Then it compares multiple characters by OR-ing the differences and comparing to zero. It has hand-optimised assembly for SBCL so that it only does a comditional jump every four characters (if I remember correctly)
10:22:16
loke
teh code contains this comment, showing the output: https://gist.github.com/lokedhs/beddab3cdfbc72ebcad9df72939efd80
10:26:15
loke
makomo: Please do, because last I looked at it, changes in recent SBCL has reduced the performace of it. It's still faster than your typical macro, but the hand-optimised version of NUMERIC-CHAR= doesn't seem to be applied correctly, causing more conditional jumps than it used it.
10:26:51
ludston
That's pretty neat. I wonder if it could be generalised to deal with other lists, or even trees.
10:27:03
loke
I think it's because some of the internals that he was using have changed. If you can fix that, you'll be a hero :-)
10:31:23
ludston
It's a bit complex. I wonder how close the output is to something like (case (aref input 0) (#\f (when (eq (aref input 1) #o) (case (aref input 2) (insert rest of tree here)))))
10:36:52
ludston
Oh you can see the macro output just aboe the assembler output. I can answer my own question. Yes it is pretty much identical to that, but for some reason he's gone with numeric-char= instead of doing a lookup
10:41:36
ludston
Because he thinks that doing 6 separate char= comparisons is going to be faster than #'equal?
10:43:42
ludston
I don't understand lol. Why be like, "I know how to compare strings faster than the people writing the compiler"?
10:49:17
jmercouris
I'm trying to understand how to use the default database configuration in Caveman2: https://github.com/fukamachi/caveman#database
10:49:38
jmercouris
I've edited my config.lisp file to have a database: https://gist.github.com/bd40654c9256e2556554a37a8ee7a98a
10:50:12
jmercouris
the thing I don't understand is this sentence: "db in a package myapp.db is a function for connecting to each databases configured the above."
10:50:25
jmercouris
and then it shows the following snippet below: "(use-package '(:myapp.db :sxql :datafly))"
10:51:53
jmercouris
seems the function does exist, just wasn't being picked up by company, had to look for it in the source
11:21:52
jmercouris
shrdlu68: Well, I'm in a slime repl, and then calling the function to launch my application
11:24:21
jmercouris
when I say env, I mean environment variables, like `set --export some-var some-value` in a normal shell
11:24:55
jmercouris
so I can't just set some environment variable in my .bashrc .profile or whatever
11:25:36
shrdlu68
I don't think you share the same env as emacs, since your implementation is exec'd.
11:26:14
shrdlu68
One way would be to launch your implementation with the variables, like "FOO=BAR /usr/bin/sbcl"
11:27:26
shrdlu68
I don't think it's possible to "inject" environmental variables, except by manipulating the data structure that holds the environmental variables.
12:23:10
dim
Xach: hi! do you know off-hand how to implement streaming uploads with zs3? by that I mean that you only ever have a small part of the content to upload in the client's memory...
12:38:47
Xach
dim: Hmm, I don't know, sorry. I'd have to look at what drakma provides and how zs3 uses it.
12:39:11
Xach
dim: i know there are chunking upload APIs that could be used regardless of what drakma provides, but i also know that is not in ZS3 right now.
12:43:45
dim
yeah I was thinking about https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html “Multipart Upload Overview” specifically
12:44:34
dim
I don't think I can use drakma level facilities here, the whole point is that I don't know the size of the content I am uploading until the end, because I am already receiving the content in a streaming fashion
12:45:36
dim
I could always use my already existing batch facility and create multiple S3 files, one per batch, and manually consider them as a multiple upload thing, though
12:46:04
Xach
dim: Interesting. I haven't thought about how S3 supports incoming objects of unknown size.
12:47:25
dim
apparently you can upload up to 10_000 chunks of 5MB content, and the last chunk “closes” the multi-part upload, and it can even be done in parallel
12:49:25
dim
my use case is (of course) pgloader related: a customer needs support for AWS Redshift as a target; and I just discovered that Redshift (a fork of PostgreSQL 8.0) doesn't have the COPY FROM STDIN feature, instead you need to COPY FROM S3://, basically
12:50:00
dim
so I'm going to do MySQL | S3 | Redshift, all in streaming, and without having to load the full contents of a MySQL table in pgloader memory if I can avoid it, of course
12:52:51
dim
well it's a SMOP as they say, and if using the S3 multipart upload protocol isn't possible with current zs3, I think it's going to be easier for me to do something that looks like it with plenty of "small" objects that are manually managed in pgloader, I don't actually need any other tool to see that as a single file per source table anyway, and also I will be able to have more concurrent processing
13:39:59
pjb
Full name is better than abbreviation, because full names can be found in dictionaries.
13:42:03
pjb
google for bhattacharyya and you find it directly. Google for bhat, bhat-dist, anything and you're lost.
13:42:26
pjb
shka: so indeed, you could even name it bhattacharyya-distance since bhattacharyya is a proper name actually.
13:44:07
MichaelRaskin
shrdlu68: those who try to cut distance out of Hamming distance will be punished by coding FFT with Hamming window
13:46:30
pjb
Modern editors and IDEs have a lookup function that will search in dictionaries, wikipedia, google the current selection (or symbol-at-point).
15:07:30
makomo
do you guys think there will ever be an effort to create a new/revised CL standard? how realistic is that?
15:08:20
Bike
there are several efforts. it's pretty unlikely they'll be at the level of an ANSI standard, though.
15:10:57
makomo
beach: oh, i hadn't thought/forgot that WSCL fits that purpose. so WSCL is definitely not "just another Lisp implementation"?
15:16:30
dim
maybe even a run-program facility as in uiop, and something to access the environment variables... basically I was pretty happy about what https://libcork.io provides for C, and including that scope into a CL “standard” of sorts strikes me as a good idea…
15:16:34
sjl
Would a new CL that included all the commonly-used things (bt, usocket, gray streams, etc) be a Common Common Lisp?
15:44:04
sjl
is it possible that every combination of c/2/t/l is meaningful, much like the c(ad)+r family?
16:24:10
defunkydrummer
sjr: in truth today we are at ctlt3 level: most implementations implement cltl2 and a lot of extras that are almost portable thanks to portability libs. I don't think the state of the language is a problem at all.
16:49:45
phoe
there's a de facto standard that all modern implementations comply to; it's implemented by c2mop, usocket, bordeaux-threads, lparallel, trivial-gray-streams, trivial-garbage, ASDF, UIOP et cetera
16:56:22
vtomole
How would that work? Is it "If your implementation implements the standard, you can pretty much add anything else you want to it"?
17:00:11
Bike
as long as the extensions follow certain limits, like not putting extra symbols in the CL package
17:12:03
aeth
Well, it's finite, isn't it? A symbol is produced from a string so the maximum length is probably array-total-size-limit. In SBCL, that's 4611686018427387901, which is probably the maximum possible in 64-bit systems
17:13:17
aeth
Or close to it. most-positve-fixnum is 4611686018427387903 in SBCL and SBCL uses (signed-byte 63)
17:14:52
aeth
If you wanted to define all of them, though, the real problem is char-code-limit, which is a lot less straightforward.
17:17:49
warweasle
aeth: I actually like the kitchen sink approach. I usually have to include a ton of libraries to get anything done in other langauges. With lisp, it's just there.
18:52:39
comborico1611
phoe: I was just trying to figure this out. Thanks! I needed the verbose to understand.
18:56:41
aeth
Depending on what you're doing you could also use types. e.g. (let ((x 'foo)) (check-type x (and symbol (not null))) x)
18:57:24
aeth
That would be if you wanted a correctable-at-runtime error if it's not a non-nil symbol
19:04:26
aeth
stylewarning: (multiple-value-bind (value value-present-p) (gethash symbol hash-table-of-all-possible-symbols-except-nil) (declare (ignore value)) value-present-p)
19:06:06
stylewarning
(let ((tbl (make-hash-table))) (do-all-symbols (x tbl) (when x (setf (gethash x tbl) t))))
19:10:12
aeth
stylewarning: now we just need a way to not have to regenerate the hash table each time the function is called (what if someone adds a symbol?)
19:34:32
potatonomicon
is there a way to make sbcl yell at me if it can't do tail recursion optimization? or does it do this by default and I just haven't seen it?
19:36:21
aeth
If it's just SBCL you could parse disassemble (keep in mind that the case of its output depends on the value of *print-case*)
19:37:35
potatonomicon
don't really want to manually check the asm, since I will have a lot of functions that need this
19:37:44
cgay
You could test your function with something that would cause extremely deep recursion. :)
19:39:10
aeth
potatonomicon: well if it's tail on itself you'd just have to look for something like this: ; 9A: B8B84C5120 MOV EAX, #x20514CB8 ; #<FDEFN FOO>
19:39:45
aeth
That's present in this unless I (declare (optimize (speed 3))) in the function: (defun foo (x) (unless (<= x 0) (foo (1- x))))
19:45:45
phoe
potatonomicon: note that the CL standard does not promise you that your code will be tail-optimized. An implementation may decide not to do TCO for any reason, such as (declaim (optimize (debug 3))).
19:46:55
phoe
Okiedokie. Just keep in mind that your code might blow stacks if you ever use tail calls in CL in places that might be called thousands+ of times.
19:47:30
eschulte_
Does anyone know of a way to read a lisp source file to a mix of S-exprs and say strings which would include enough information to rebuild the original source (including whitespace and comments)?
19:54:22
beach
eschulte_: It can wrap the S expressions in the file in standard objects that contain information about the source.
20:06:47
jmercouris
I'm trying to convert the following sql https://gist.github.com/b2259281e4c470a3930c05166c7cb2c0 to sxql
20:08:19
jmercouris
I've got the following: https://gist.github.com/c9c50d181cccea43b26c5388af2ba2d4
20:18:21
jmercouris
keyword args are only: type not-null default auto-increment autoincrement unique primary-key
20:57:14
jeosol
One of them said he is no longer associated with it, referred me to another dude, who said he does not know how to reach the maintainer
20:57:42
jeosol
It is seems it is round and round so far. But I may just pick it up and proceed as discussed
20:58:12
jeosol
I can pick it up, I just don't want to have issues with that maintainer who I can't reach so far
21:00:03
jmercouris
I guess since you will be the author, you may package and license it in different ways
21:00:20
jeosol
that was the plan, as long as they are willing to relax or work around it. One of the dudes said it was possible, but he is not longer involved
21:01:21
jmercouris
it really depends on what you are going for, whether you want to actually get something done or not