freenode/lisp - IRC Chatlog
Search
2:41:31
Alfr_
dbotton, even (defconstant foo 12) (setf foo 13) doesn't need to trigger an error. It's only undefined behavior.
2:42:33
aeth
implementations are afaik permitted to add a (declare (whatever foo)) if they wanted to
2:48:00
dbotton
is there a reason why the standard felt the need for a deconstant but not on a local basis?
2:48:11
aeth
I don't think there's a way, but (declare) is valid so if you had to do (let ((x 1)) (declare #+your-cl (immutable x)) (setq x 10)) you could still write perfectly portable code here.
2:49:22
aeth
(and I think they're supposed to ignore unrecognized forms inside of DECLARE, so I think but am not sure, that that would just be a warning if you didn't do that)
2:51:51
aeth
Anyway, that's probably my guess as to why it's not in the standard. Because they probably anticipated that they didn't create an exhaustive list of useful declarations
2:59:09
aeth
dbotton: Sorry, what I mean is I don't think there was a particular need to include this in the standard since it gave implementations the power to add it, and they probably weren't really thinkinng about this sort of thing 30 years ago.
3:00:16
aeth
dbotton: You could also, yourself, create a macro that does this without even code-walking, since DEFCONSTANT exists. Just symbol-macrolet
3:02:11
aeth
dbotton: So I guess there is a way to mark a variable as a constant if you're willing to have a hidden DEFCONSTANT variable
3:10:20
aeth
dbotton: probably depends on the implementation because it says it's undefined in the spec, but it's an error in SBCL. e.g. (defconstant +foo+ 42) (defun foobar () (symbol-macrolet ((foo +foo+)) (setf foo 43)))
3:15:29
aeth
it solves the specific problem, but not the general problem, so maybe it's good enough depending on the task
3:20:24
aeth
dbotton: Sorry, I realize I didn't directly answer your question. It's a compile time error because it's an error when I DEFUN, which won't call the code directly
3:26:10
Bike
not really. the compiler can just determine if a variable is immutable by looking at how many places it's assigned.
3:27:51
aeth
the symbol-macrolet to a defconstant should produce the same code in an optimizing compiler (SBCL at the very least)
3:28:42
aeth
If you want more, you'd want an immutable type so it can be optimized outside of a function's scope, too.
3:38:10
dbotton
I have not yes started on clos, so sorry if this is ignorant, would it be possible to extend a built in type and then declare type it on the new type?
3:39:36
aeth
The thing itself always has a type, and the binding can have a type if DECLAREd (technically, it always has it, but it's normally T).
3:40:28
aeth
So the type declaration doesn't have an impact on the object itself, except that it might error if it mismatches (and it might not... only CHECK-TYPE guarantees the type error)
3:42:54
dbotton
I realize this is probably the wrong though process to start with for Lisp, ie trying to type the variable not the data
3:43:03
aeth
For the other part of your question, afaik, you normally can't extend built-in types, but sometimes you can, such as trivial-gray-streams or trivial-extensible-sequences
3:43:43
beach
dbotton: I think you are right. It is common for people coming from other languages to overuse type declarations.
3:44:12
aeth
Generally, type declarations should only matter if for arrays/vectors, numbers, and arrays/vectors of numbers
3:44:36
aeth
At least as far as performance is concerned. Otherwise, the added checks might actually deoptimize the code.
3:45:15
beach
dbotton: I read somewhere that languages with manifest typing force the programmer to come up with types that may not be true later on in the development process.
3:49:47
beach
dbotton: yes, you came to the right place since you can do arbitrary computations at compile time.
3:50:07
aeth
You can force someone to win a (complete, graphical) game before the code compiles if you want to. Just put a call to launch the game in an EVAL-WHEN.
3:50:59
dbotton
In Ada it is all about using the Type to insure correctness of code, a form of compile time computing that has worked very well for me
3:52:01
dbotton
I think once I have fully groked the CL approach will open something open in the avenue more
3:52:10
beach
dbotton: I am curious, then, as to why you want to use Common Lisp, and why you are trying to do the same things with Common Lisp that you have been so successful with using Ada.
3:53:35
dbotton
I have a lot of experience with C/C++ other languages as well, the Ada approach worked well, but realized I never actually learned lisp all these years
3:54:27
beach
dbotton: Then I seriously suggest you try to use it as it is normally used, rather than trying to emulate the Ada programming style with it.
3:56:53
dbotton
few other reasons interested me in lisp, age of standard, number of implementations available, quality of tool sets etc
3:57:16
aeth
dbotton: imo, there's a bit of a tension in Common Lisp between interactive development and compile time computation... both are more of a priority in CL than in most languages.
3:57:33
aeth
Interactive development means you can redefine things and you want to be able to have fast compilation times.
3:58:44
dbotton
My approach for my personal projects has been a very lisp like one even the Ada very ridged
3:59:35
dbotton
But being forced in to the type model has also improved the quality of the results I think
4:00:48
no-defun-allowed
A dynamic approach might be better if, by the time you would come up with a model to show correctness with, it wouldn't reflect on your current requirements. And there aren't any type systems that I know of that will let you migrate state from one model to another like in Common Lisp.
4:04:43
dbotton
beach, the other reason for the switch is Ada is now for all intensive purposes a one vendor product and they have more or less specialized in one niche
4:10:07
dbotton
These days I make my living for the most part outside the computer world so I can "afford" to invest in something more then job easy languages also
4:10:28
no-defun-allowed
In my probably significantly shorter experience with Lisp, the SBCL compiler catches type errors (on functions involving inbuilt types), or I can provoke them by poking at them with a REPL in about a minute.
4:10:54
no-defun-allowed
Though I heard Ada also has some more in terms of formal verification tools than other static languages.
4:12:52
beach
dbotton: For compile-time computations, I recommend the book "On Lisp" by Paul Graham.
4:13:10
aeth
There's no reason why there couldn't be a CL with even more static verification than SBCL
4:18:53
no-defun-allowed
Oh, also note that if I find an error like that, the thread that signaled an error pauses and I'm presented with a backtrace and some restarts, which usually suffice to test a solution without stopping the program. That is mostly non-present in most dynamically typed languages (I hesitate to call them "dynamic languages"), which makes them the "worst of both worlds", as they are apparently unsuitable for static
4:25:26
dbotton
So to sum up, interests are the general approach to development is like what I have used for years, the tools are there, the quality of tools is there, the quality of community supporting the tools is there, the language is ideal for my current interests in general ie compile time computing, and believe Lisp a good long term host for my creative
4:26:18
dbotton
the only negative, and probably singe reason never looked in to it, the readability of it
4:26:54
dbotton
I stumbled on Ada because felt that recording my ideas in a human readable language a good idea
4:27:25
no-defun-allowed
I never found precedence rules particularly friendly, but it's open for debate if I'm a "human".
4:27:26
dbotton
and it is the most readable of any language with a good modern toolset and at the time looked promising
4:29:41
dbotton
thank you all though for the direction and knowledge, still have much more to go before can similarly contribute
4:30:02
no-defun-allowed
Like, in mathematics classes I'd have written out long equations that weren't in a nice form, and couldn't parse it later. Then everyone else tells me that parenthesised prefix notation is harder.
5:40:40
dbotton_
interesting p17 of lisp 1.5 manual has discussion of making constants. I assume technique wouldn't work with current implementations
5:44:36
dbotton_
(I know 1.5 not CL but for me need to understand the why's and that comes from history)
10:30:11
jmercouris
hello everyone, short article we wrote about how we implemented hooks: https://nyxt.atlas.engineer/article/hooks-implementation.org and how we merged them into serapeum
10:48:33
scymtym
article: "During the development of Nyxt we quickly felt dissatisfied with our initial hook implementation (based on Emacs)." second sentence of the linked issue regarding merging into serapeum: "In Next we use https://github.com/scymtym/architecture.hooks"
10:58:43
phoe
I understood it more like "we first used a custom emacslike implementation, then used scymtym's hooks, and now we use this current implementation from serapeum"
11:02:46
scymtym
phoe: i understood it that way as well, because i was involved and already knew, but i don't think you could get that from the previous version of the article. making the influences clear seems important since, for example, scymtym/architecture.hooks was modeled after generic functions and to some extent Boost.Signals rather than what Emacs does
11:04:26
scymtym
jmercouris: sure (i currently get a 502 for the URL, so i couldn't look at the revised version)
11:47:21
beach
jmercouris: There is no such thing as "a lambda" in Common Lisp. Maybe there is in Emacs Lisp, but not in Common Lisp.
12:59:02
beach
It would then be better to use the correct terminology, and add notes about names of similar constructs in other languages.
12:59:33
phoe
Would anyone be interested in reviewing my first/newest book, "The Common Lisp Condition System", on Amazon? The deal is that Apress can offer free ebook versions of the book to some people, and they would like to get a review posted on Amazon in return.
13:03:16
drmeister
How worried should I be about reproducibility of random number sequences generated using (random <x> <random-state>) where I load <random-state> from a saved <random-state>?
13:03:54
drmeister
It's arithmetic right? Completely deterministic. I should be able to reload a random-state 10 years from now and generate the same sequence if the random number generator algorithm hasn't changed.
13:04:24
phoe
Notes: One important use of make-random-state is to allow the same series of pseudo-random numbers to be generated many times within a single program.
13:05:05
phoe
"A random state object contains state information used by the pseudo-random number generator."
13:05:31
phoe
so, yes, if the algorithm has not changed then knowing the random state is enough to reconstruct the PRNG state
13:06:24
Xach
by "your own" i don't mean write your own, i mean use a RNG library that someone else wrote, and that you can fully understand and control
13:06:31
phoe
but then you need to assume that your lisp implementation that'll exist in 10 years from now will have no changes to its algorithm
13:07:49
drmeister
Since I control the lisp implementation I could make sure the algorithm doesn't change. We are using the boost::random library.
13:13:06
_death
often there's benefit from using your own.. for example I recently switched to using a xoshiro implementation in a program that resulted in a significant speedup, and it also solved the issue of initializing the random state to a particular one throughout runs (can usually be done, nonportably)
13:13:06
drmeister
Using the mersenne twister means I'll get the same random number sequence on whatever it runs on - right? Say we move Cando to ARM - the same saved random-state will get me the same sequence of pseudo random numbers. Correct?
13:14:20
Bike
a PRNG is basically deterministic. it's just an algorithm that outputs a sequence of integers based on an input state
13:14:42
drmeister
I added the ability to readably print and read random-state yesterday (it was an oversight for a long time).
13:15:51
Nilby
This is one of the reasone people make secure enclavess with their own chip. Maybe the best thing to do is test that your same random code & state produces the same results.
13:16:43
_death
drmeister: for fun, here's a way to reconstruct mt19937 state from 624 consecutive outputs: https://gist.github.com/death/9c11ffb8594e91dfbe7b6e9baf0cbc31
13:17:25
drmeister
I want to use a random-state as the seed for generating molecular sequences that will be difficult to impossible to reverse engineer.
13:18:36
drmeister
I will write out the sequences - but they will be generated from the random number generator - if they became inconsistent - there would be trouble.
13:20:23
drmeister
I don't have 624 consecutive outputs at this point - I have around 360 and they are each modulo some value.