libera/#commonlisp - IRC Chatlog
Search
3:21:14
phantomics
Here's a question that's kind of the opposite of yesterday's: when I have a dynamic variable with a definition assigned to it that's effective within a scope, is it possible to set the variable's top-level value from inside the scope? Here's an example:
3:21:24
phantomics
(defvar ab 10) (funcall (lambda (a) (let ((ab ab)) (set-toplevel ab 20) (+ a ab))) 15) ab
3:22:26
phantomics
The (set-toplevel) is a theoretical macro that sets the value of ab at its top level so the end result of this will be 20. If setf or (set (symbol-value ...)) is used in place of set-toplevel, the result is always 10
3:23:55
beach
There is no standard way. But the implementation may have something. Most implementations would assign to the top-level binding if you create a new thread and do it in that thread.
3:26:33
phantomics
Was confusing because the nesting looked right, realized I couldn't get the variable value I wanted because threads were being spawned inside one of the functions
3:27:38
phantomics
That's a pain if the implementation can't be counted on though, I may have to find another way
3:29:26
phantomics
In APL it's possible to assign both values that are scoped inside a function and the top-level dynamic variable outside a function using different syntax
3:31:04
phantomics
Outside-scope assignment is a fairly obscure thing to do anyway, I can just implement it with a thread and see if there's ever a problem
3:31:17
jcowan
beach: What I expected to find in the inlining paper was a discussion of inlining functional arguments, as when you want to inline a call (mapcar car list-of-pairs), where you could not just inline mapcar but also inline car within it.
3:32:09
mfiano
I mean you are basically accessing for a dynamic variable to not be dynamic, so you'll have to use additional storage
3:35:07
phantomics
mfiano: yeah, I'd need two defvars, and I'd have to remember to reference the top-level variable in the (let) block of any function definition done at the top level
3:35:54
beach
It is not clear to me whether those two affect the innermost binding or the top-level binding.
3:36:01
jcowan
phantomics: If your macro expands to two defvars, it should instead map to (progn (defvar ...) (defvar ...))
3:36:01
mfiano
beach: defparameter as a non toplevel form does not have to recognize that the variable should be special
3:37:57
mfiano
beach: "However, the compile-time side effects described below only take place when they appear as top level forms"
3:42:04
beach
Note to self: In WSCL, specify which binding is affected by non-top-level DEFPARAMETER and DEFVAR.
3:46:35
moon-child
phantomics: you might consider not relying on cl's dynamic scoping, and instead using your own binding stack
3:47:32
moon-child
alternately, use some standard prefix for local variables (use a separator, like +; even if you allow rebinding +, you will never allow rebinding ++, so it avoids collisions)
3:52:05
beach
phantomics: Maybe. But it is often a bad idea to rely on the semantics of the implementation language matching the language being implemented.
3:53:27
moon-child
first: there are certain things that it makes sense to rely on. Integer arithmetic, for instance
3:53:56
moon-child
second: if you are designing a language that integrates closely with its target (as april seems to with cl), then it makes sense to try to express things idiomatically in terms of the target, where possible
3:54:07
beach
Oh, I didn't mean the way certain functions work. I was referring to the overall semantics.
3:56:40
phantomics
Orthogonal in that many of the concepts are 1-1 mappings. a+⎕←b×c is the same as (+ a (print (* b c))) for example
4:00:27
phantomics
April produces CL arrays you can easily interact with in CL, its workspace are CL packages. APLs implemented in other languages make special data structures that you can't process using the host language, especially since most are written in languages that don't support multidimensional arrays
4:01:51
moon-child
well, depends on what you mean by 'process using the host language'. Dyalog apl (for instance) is written in c++; its arrays are implemented in terms of c++ structures and are surely manipulable from the (c++) implementation
4:02:24
mfiano
Right. When I see "orthogonal" I think geometrically, as in, on an orthogonal axis, not even comparable.
4:04:48
phantomics
I remember hearing it used differently. I would say instead that APL parallels Lisp in many respects
4:06:25
moon-child
now I am thoroughly confused. I would say that apl parallels lisp in one respect (power derived through manipulation of a homogenous data structure) and almost no others
4:07:18
phantomics
Their history is kind of similar too: both are mainframe languages, both were used essentially as operating systems and frontend user interfaces on their host machines. Both fell out of favor when the microcomputer revolution happened due to needing a powerful computer to be useful
4:08:06
moon-child
(though lisp did a better job of surviving, I think because it was academic so there were free implementations)
4:08:47
phantomics
Vector languages have traditionally been more proprietary than other language families, see k
4:09:38
phantomics
Also, APL has historically mostly been an interpreted language, deploying it means you have to deploy interpreters. It also means there are a few APL features you can't implement with a compiler
4:09:39
moon-child
yes. But I mean originally, lisp was used for ai at universities, and apl was used for finance at businesses, and this was in the era before commercial languages were generally opensource
4:10:04
moon-child
there were a few historical apl compilers. One I was even able to dig up source for (though I couldn't get it running)
4:16:26
phantomics
To me the main similiarities between the languages are their simple syntax and how they model arrays and functions. Working on them "feels" similar, even if the appearance of the code is very different. Especially because both are designed around a REPL.
6:43:28
gigo
Why should we use with-standard-io-syntax when not using it also works fine. Code I wrote to test it out: https://plaster.tymoon.eu/view/2506
6:46:51
kakuhen
phoe: i am trying to bootstrap 1.12.1 and I kept running into a bunch of mysterious compiler errors; so far i have managed to produce the 1.12.1 kernel and some bootstrapping binary from my existing ccl installation
6:47:28
kakuhen
somehow (ccl:compile-ccl) immediately gave me some error about x8664arg something, but (ccl:compile-ccl t) went smoothly
6:49:05
kakuhen
what i've done so far is merge my /usr/local/lib/ccl with the ccl-1.12.1 folders, but obviously not overwrite any overlapping files
6:50:26
phoe
the general procedure of bootstrapping CCL is, you use the existing CCL to build a new minimal heap image, and you compile the C kernel
6:51:50
kakuhen
Anyway, I ran the 1.12.1 kernel with the 1.12 heap image, and then I ran (ccl:xload-level-0), which compiled all the newer lisp files without error and produced a bootstrapping image
6:52:03
gigo
mfiano: phoe: So if I don't change the default IO settings, then not using (with-standard-io-syntax ...) would be okay?
6:52:12
kakuhen
phoe: im assuming i should be using this bootstrapping image when I invoke (ccl:compile-ccl) and not my 1.12 heap image
6:52:42
phoe
I think the bootstrapping image only contains enough facilities to be able to load FASLs
6:52:44
gigo
phoe: makes sense. thanks. so I should keep the (with-standard-io-syntax ...) as a best practice.
6:54:39
kakuhen
running (ccl:compile-ccl) gives me "Error: Unbound variable: $NUMX8664ARGREGS signaled during assembly-time evaluation of form (* $NUMX8664ARGREGS X8664::NODE-SIZE)" when its trying to compile x86-clos.lisp
6:54:46
mfiano
gigo: if your code has (float x 1.0) and isn't wrapped in with-standard-io-syntax, the user could change that by dynamically binding the float read format around a call to your function
6:54:52
kakuhen
But what I find confusing is that running (ccl:compile-ccl t) gives zero errors whatsoever.
6:58:16
kakuhen
phoe: OK turns out my cursed method of merging folders worked and produced me a 1.12.1 binary
6:58:26
kakuhen
you were right about the bootloader only being able to load fasls and do basic functions
6:59:12
kakuhen
The manual makes me believe that calling "(ccl:compile-ccl)" should recompile updated lisp sources and generate fasls for them
6:59:25
kakuhen
yet it has this strange error for x86-clos.lisp, unless you force compile EVERYTHING
7:01:01
gigo
mfiano: Can you give an example of *read-default-float-format* that can make the writing and reading incompatible (provided I don't use with-standard-io-syntax)?
7:03:24
phoe
gigo: I think (setf *print-length* 3) is a simpler example - you simply cannot read back lists that have been truncated like this, no need to play around with float formats
7:04:34
gigo
phoe: Yes, I tried (setf *print-length* 3) and it indeed breaks the reading. This helped. Want to try out an example with *read-default-float-format* too.
7:12:52
gigo
I will make something out of that example to convince example. Thanks for the example. I am first writing some examples to understand the difference between single-float and double-float.
7:19:41
phoe
gigo: double floats have more precision but cannot be immediate values on 64-bit platforms
7:24:04
kakuhen
Here is a full log of everything I did to bootstrap v1.12.1 from v1.12 https://bsd.to/wXwJ
7:24:15
kakuhen
Before running this, I uninstalled ccl and then reinstalled ccl (1.12) from freebsd ports
9:36:17
gigo
mfiano: phoe: In our discussion a little while back I learnt that if I don't use (with-standard-io-syntax ...) while writing to a file, reading it may become impossible. Is there an example where if I don't use (with-standard-io-syntax ...) while reading, it may cause problem?
9:42:53
susam
phoe: so not something straightforward a beginner like me can reproduce easily? that's fine. I will keep it in mind and try it out later when I have learnt more CL.
9:43:25
susam
phoe: this discussion has been most interesting. Unfortunately I have not learnt reader macros yet.
9:44:49
susam
In fact, it never occurred to me earlier that with-standard-io-syntax was important while reading and writing files. I guess because I mostly write them out in a custom format that I have to parse. But yes, after the few examples cited earlier today in this channel I see why it is important.
9:48:44
gigo
phoe: https://plaster.tymoon.eu/view/2507#2507 - this works fine. what kind of mismatch should I make?
9:50:26
phoe
(let* ((string (prin1-to-string 1.0f0)) (*read-default-float-format* 'double-float)) (read-from-string string))
10:37:13
gigo
phoe: learning CL and I had a nagging feeling since yesterday that I don't fully understand the need for with-standard-io-syntax. but now I do after reading the examples you gave. thanks!
10:40:25
kakuhen
How many people actually read documentation slots in CLOS, let alone know how to access them?