On Tue, May 31, 2022 at 09:44:12PM +0200, Ralf Hemmecke wrote:
> Dear Waldek,
>
> In Stream, I see
>
> -- This description of the rep is not quite true.
> -- The Rep is a pair of one of three forms:
> -- [value: S, rest: %]
> -- [nullstream: Magic, NIL ]
> -- [nonnullstream: Magic, fun: () -> %]
> -- [uninitializedstream : Magic, 0]
> -- Could use a record of unions if we could guarantee no tags.
>
> NullStream : S := _$NullStream$Lisp pretend S
> NonNullStream : S := _$NonNullStream$Lisp pretend S
> UninitializedStream : S := _$UninitializedStream$Lisp pretend S
>
> Rep := Record(firstElt : S, restOfStream : %)
>
>
https://github.com/fricas/fricas/blob/master/src/algebra/stream.spad#L626
>
> And also
>
> -- we have to use SPADCALL directly to avoid wrong code
> lazyEval x == SPADCALL(rst(x))$Lisp pretend %
>
>
https://github.com/fricas/fricas/blob/master/src/algebra/stream.spad#L626
>
> May I ask whether
>
> lazyEval x == (rst(x) pretend () -> %)()
>
> would actually also work? Or is it that what produces wrong code?
Well, we had
lazyEval x == (rst(x):(()-> %)) ()
':' was doing what you apparently think that 'pretend' would do.
':' is gone, IIRC 'pretend' failed, so that is why we have SPADCALL...
There is extra thing: now we generate Lisp type declarations based
on Spad types. If there is enough type information and one uses
'pretend' to cheat about types, then we may get wrong code from
Lisp compiler (like type error in safe mode, crash in unsafe mode).
> The idea in Stream's representation is anyway that values of type % and
> values of type ()->% can be stored in the same record position.
>
> I am asking, because that would eliminate an explicit SPADCALL$Lisp.
Well, this is one of darkest corners in our code.
> In fact, I'd be happy, if all the function that are Lisp-specific like
> EQ$Lisp, APPEND$Lisp are defined at the beginning and then no further
> ...$Lisp will appear.
Well, one possiblity is to have small number of "primitive"
domains, say "BuiltinInteger", "BuiltinSymbol", "BuiltinList".
The idea being that only "primitive" domains can directly use
Lisp operations. And if we provided non-Lisp implementation
of builtin domains then the rest of algebra would work
without Lisp. However, that is future.
I am affraid that 'lazyEval' would have to be part of
"BuiltinStream"...
--
Waldek Hebisch