libera/#commonlisp - IRC Chatlog
Search
22:12:42
hendursaga
Anyone aware of some CL equivalent to this? https://github.com/jgoizueta/sys_cmd
22:13:18
hendursaga
Basically a DSL for 'building up' commands + their arguments to be called on a shell
22:18:21
Alfr
hendursaga, you're after the escaping part of it? Maybe uiop:escape-shell-command fits your needs?
22:20:37
hendursaga
Alfr: like, some kind of macro that takes something say unix-opts might use to parse command-line arguments, but instead of parsing, generate a function that would take in arguments and then output the string of the resulting command to call externally..
22:21:10
copec
hendursaga, I would google using common lisp as shell, I bet that would link to lots of useful things
22:22:52
Alfr
hendursaga, I don't understand what that function is supposed to do. Query a user for the arguments separately?
22:41:47
Alfr
hendursaga, from that package's description and the listed examples, I don't see how that project you linked does anything more than (except for being really verbose): (let ((s (uiop:escape-shell-command '("echo" "arg1" "arg with spaces")))) (uiop:run-program s :force-shell t :output 'string))
23:28:13
Nilby
Psybur: Yes, if you allow nesting of them, they have the same properties as lambda calculus.
23:41:02
edgar-rft
Psybur: if no skilled Lisp archaeologists show up in the next minutes, you can try yourself here -> http://www.softwarepreservation.org/projects/LISP/
23:49:55
Nilby
Psybur: The requirements for lambda calculus are fairly low. Anything that allows variable substitution and function application. Literal encapulation can be used in place of recursive function application, but of course it's quite tedious to construct things.
0:08:03
dieggsy
edgar-rft: it's like strftime, the other way around. e.g. if you give it "2018-12-01" and "%Y-%m-%d" it would spit out a date time object
0:08:42
dieggsy
idk why i've suddenly taking to using "spit out" instead of return, it's rather icky sorry lol
0:10:23
edgar-rft
don't know about allegro but local-time might have such a thing -> https://www.cliki.net/local-time
0:12:23
dieggsy
i try to avoid using extra deps where possible but good grief do we need a proper date/time handling library
0:13:11
dieggsy
we have a bunch of hacked together ways of detecting and converting date formats across several files and it's .... less than ideal
0:14:28
edgar-rft
I also try to keep external dependencies as low as possible but writing your own time/date handling rather quickly becomes an enterprise in itself :-)
0:21:16
dieggsy
there's multiple functions that do the same things, none doing it particularly well or strictly validly lol
0:24:15
edgar-rft
another fun is that in most networks every computer uses its own built-in hardware clock for the time and the clocks are rather seldom synchronized with each other
0:26:18
dieggsy
but i've been doing some tests and who knows how allegro is interpreting (date-time "20-800") lol. "20-200" is the 200th day of 2020...800 ... wraps around maybe? lol
0:27:55
Nilby
There was a good date/time string parser on old lisp machines, but it's much much harder to do now, since you have to know and allow locale and language and cultural specific formats, calendars, etc, and also things like do you allow things like 2 leap seconds?
0:28:50
mfiano
There is a Common Lisp book dedicated to calendrical calculations on my bookshelf I've been meaning to read.
0:37:11
mfiano
Here it is. Well, apparently there is a newer edition now, but I don't know what is different: https://www.amazon.com/Calendrical-Calculations-Nachum-Dershowitz/dp/0521702380
0:37:32
mfiano
One review: "However, some of the calculations are very complicated and it was difficult to translate these from the LISP listings in the book into PHP or Javascript."...
0:40:18
jcowan
Just handling the Gregorian calendar and its near relatives is hard enough. Mayan, fuggedaboudit.
0:46:35
Nilby
It's quite a bit of work to parse "2021年 9月 28日 火曜日" and "mar. 28 sept. 2021" and "Tue 28 Sep 2021" and "22 صفر 1443"
1:00:20
jcowan
THere are just so *many* parameters, some of which are locale-specific, others situation-specific. The U.S. is an m-d-y locale, but there are many ways to write it: September 28, 2021 or Seo, 28, 2021 or 9/28/2021 or 9/28/21 or 9-28-21 ...
1:08:55
hayley
It can be used to count the number of some resource available, and have threads wait until resources are available.
1:10:08
hayley
Well, a lock prevents concurrent access to one "resource", like a shared database. You could use a semaphore for more "resources", like elements in a queue.
1:13:55
seok-
Can I understand semaphores as just a thread-safe integer variable which counts the number of threads working on a function ?
1:15:12
hayley
You can release a resource and increment the counter, or acquire by trying to decrement the counter if it is positive, or waiting if it is not.
1:16:49
hayley
As I said, you can handle multiple resources, like multiple elements in a thread-safe queue, with a semaphore.
1:17:29
seok-
so the difference would be that, locking a variable will apply only to that one resource
1:17:53
mfiano
which is also a mutex, but a semphore is more general, because in a mutex for example, only the thing that locked a resource should unlock it
1:22:04
mfiano
ACTION doesn't do much multi-threaded programming these days, and when i do, i cheat and reach for lparallel, or "hardware mutex" atomics.
1:45:52
hayley
I've only really used semaphores indirectly through thread-safe queues, and occasionally I do nitty-gritty concurrent stuff.
1:50:32
akater[m]
Is there a codified Lisp indentation style guide? In particular, I'm interested in line splits. E.g. there is a practice of keeping “then” on the same line as “if” sometimes but it's sort of unofficial. I can't find any document that would consistently describe various Lisp indentation practices.
1:52:44
hayley
I know in the SICL style there is a linebreak in (loop for x in xs <linebreak> do ...) but it is not mentioned in the Specification.
1:52:58
moon-child
akater[m]: line splits are a matter of personal style, and the complexity of the expressions in question
1:53:39
moon-child
if the condition and the true branch of an if are simple and short, I would put them on the same line. If either is complex or contains many terms, I would put them on different lines
1:55:36
moon-child
(and if all are quite simple, put the else branch on the same line as well. Ditto the body of a loop, contra hayley's note re sicl style guide)
1:56:31
akater[m]
moon-child: I still wonder if there's any text describing Lisp indentation practices. There is personal style but there also is accumulated experience.
1:57:54
akater[m]
Keeping forms concise both horizontally and vertically by using whitespace wisely seems to be recognized as a virtue — again, only informally.
2:22:44
White_Flame
the &body form will indent only 2 spaces or so, while the non-&body tends to indent in line with the 2nd element of the list (eg, the test)
2:24:24
White_Flame
regarding linebreaks, the major thing is that open parens shouldn't end a line, and closing parens shouldn't begin a line
3:03:56
mfiano
I would urge against putting a loop clause at the end of a line, such as DO. That just makes reading harder.
3:05:34
White_Flame
if I have multiple WITH or FORs, I often do (loop <nl> for ... <nl> for ... ) to keep the header forms aligned
3:06:23
mfiano
But here the second "..." is at the end of the line, so it's fine, assuming "..." doesn't end in a keyword.
3:09:29
hayley
I put the first loop clause on the first line of a LOOP form, so (loop for ... <nl> for ... <nl> ...) The number of possible LOOP styles is huge.
3:09:30
mfiano
It even indents :when/:do and similar things that indicate nesting, assuming some SLIME variable is set, and you use keyword-interned keywords.
3:11:20
mfiano
What I was thinking of, is it will align the ":" of keyword-interned symbols on adjacent lines, with some lisp-mode variable set.
3:11:47
mfiano
Which is handy for LOOP, with keyword-interned symbols, to be more readable, like a property list with keyword symbol keys.
3:12:18
mfiano
I forget what that variable is called, or if it is now set by default (it's been like 10 years since I know for a fact it was not the default)
3:13:16
White_Flame
where every loop keyword within the form is &body-indented, not aligned to the (loop <term> ...) term
3:16:35
beach
But, yes, I agree, for other constructs I sometimes need to add a newline to get things to line up, mostly due to the brokenness of the Emacs indentation algorithm.
3:20:32
mfiano
As mentioned, using keyword-symbol LOOP keywords does help Emacs' lisp-mode indentation algorithm in certain situations.
3:41:44
dieggsy
FWIW i found this, which is rather sweet and simple https://github.com/mohe2015/schule/blob/818c0499cb6904ec5ef6d325f4636410b7fa5913/src/libc.lisp
3:42:15
dieggsy
i was leaning towards FFI anyway but i've not actually used CFFI so it certainly expedites things to find someone's already had your exact idea lol
3:57:19
mfiano
dieggsy: You would be losing a lot of the benefits of Common Lisp by punting to foreign code.
3:58:48
dieggsy
there's no built-in way to do it. there's a periods library that has a strptime but it's weirdly too permissive
3:59:20
mfiano
Yes. You can no longer guarantee that a conforming program will run N decades from now, or currently on other operating systems, such as Mezzano. Instead, use local-time.
3:59:22
dieggsy
I could certainly try and write my own CL strptime but that feels even more like reinventing the wheel
3:59:43
dieggsy
mfiano: local-time doesn't handle custom string formats, unless i missed that part of the docs
4:01:13
dieggsy
mfiano: it's not about amount - i have strings like "YY.DDD" that I need turned into some lisp time object or unix time
4:02:52
dieggsy
I was already writing a bunch of regex to handle all the cases, but i also have to validate the dates etc.
4:03:40
dieggsy
"write your own date parsing library" is historically a pretty solid way of shooting oneself in the foot though
4:04:35
dieggsy
so I was just looking at other options. perhaps strptime through CFFI isn't a good option then. but i always like to look at "short of writing it myself, what's the best alternative"
4:06:46
dieggsy
Respectfully, I disagree that it's "lazy" to not write everything yourself/investigate the alternatives, especially given that I mentioned I was already going down that path
4:07:50
dieggsy
What kind of an engineer would I be if i couldn't make the best use of the tools at my disposal, heh. Write my own tools too, sure. But they're not mutually exclusive
4:07:55
mfiano
I and many others make an effort to ensure no transitive dependency is using needless foreign code. You do what you wish though.
4:08:11
dieggsy
you make a good point about portability though so that's certainly something to consider
4:08:45
dieggsy
At the same time, there is FAR too much code in our codebase where someone went "i'll just do it myself" and it's a hot mess so
4:11:48
dieggsy
i'm doing my best to steer us right though, and i think i agree haphazardly introducing an FFI dependency doesn't do that so
4:14:09
mfiano
Sure. It just pains me when people _needlessly_ use foreign code. It only hurts the Lisp ecosystem and annoys the purists (read: most of us :)). I'm sure beach and others will chime in with more reasons when they've had their coffee.
4:14:50
dieggsy
Well, i'm certainly more of a pragmatist than a purist, but you can be one and the other, and in some cases you have to be one to be the other
4:15:21
mfiano
I've been working on a game engine for approximately 10 years now, and if I had to use foreign code, I would probably just use C, heh.
4:15:50
dieggsy
I enjoy hearing opinions in any case, even (especially?) those I might not initially be inclined to agree with. I've no real ego about my programming lmao
4:19:28
dieggsy
As a chicken schemer at heart, foreign code is one of the major selling points there
4:19:58
mfiano
For example, in my domain, game development, whenver I interface with the OS for I/O I must use C at some level, whether it's a syscall, or some hardware abstraction layer. In my case, the only foreign code I use is SDL, and it's largely unavoidable mostly due to GPU manufacturers releasing binary blob drivers.
4:21:11
mfiano
This does limit the machines that can run my code, but SDL is pretty widespread and touches everything that has a GPU driver available for it anyway, so I don't mind. It does mean though that I am at the mercy of the project unless I write an abstraction layer.
4:24:18
mfiano
Yes, it happened reliably when I dragged a window, and my X server usually runs for months at a time without an issue. :)
4:25:50
dieggsy
The other thing is you don't always have full control over your code, e.g. we depend on proprietary databases etc. anyway
4:47:07
beach
The only thing I can add, or rather emphasize, is that FFI solutions tend to benefit only the individual, whereas if that individual spent a little bit more time to create or add to a pure Common Lisp library, we would collectively benefit.
4:57:09
mfiano
I suppose sometimes an individual is a team, in which case, the decision to depend on foreign code should be more carefully weighed, and knowledge of the entire team's working environment and compatibility/issues with said foreign library in that environment.
6:03:20
lisp123
If anybody wants an Emacs shortcut to re-run the expression entered into the SLIME REPL (useful for re-running tests), you can use this (thanks pjb for parts of the code): https://pastebin.com/NJ7CE4Lx
6:06:57
lisp123
M-p is from within the REPL, this can be used from any buffer (so saves having to switch to the REPL and back) -- I may be mistaken though and there is some other way