Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

* dpkg ponders: 'C++' should have been called 'D' -- #Debian


devel / comp.lang.lisp / name? ensure compile time features are present or absent at runtime

SubjectAuthor
* name? ensure compile time features are present or absent at runtimeMadhu
+- Re: name? ensure compile time features are present or absentZyni Moë
`- Re: name? ensure compile time features are present or absent at runtimeMadhu

1
name? ensure compile time features are present or absent at runtime

<m37d9v51ik.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16853&group=comp.lang.lisp#16853

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: name? ensure compile time features are present or absent at runtime
Date: Wed, 16 Feb 2022 01:46:19 +0530
Organization: Motzarella
Lines: 85
Message-ID: <m37d9v51ik.fsf@leonis4.robolove.meer.net>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="21bfac0e0286830fef0018dd4fd9f48f";
logging-data="1545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jpG9KoIhudQCDR4XhLXYCDtlQ7MfAYNU="
Cancel-Lock: sha1:oebZ1qUiNU4EGt/T/cXrUunIMKg=
sha1:3Ur4td4rK5GOQ9ZRE8de0eKNxiM=
 by: Madhu - Tue, 15 Feb 2022 20:16 UTC

While I am a big fan of reader conditionals, I often shoot myself in the
foot by loading fasls which were compiled with (or without) a certain
feature but which do not match the features in the lisp which is doing
the loading.

My solution to this problem was to hardcode checks in the code. for a
feature foo,

#+begin_src lisp
(defvar foo-present-p #+foo t #-foo nil)
(eval-when (load eval)
(assert (eq foo-present-p (load-time-value (and (find :foo *features*) t)))
nil "Feature Mismatch: FOO was ~:[absent~;present~] at compile time but is ~:*~:[present~;absent~] at runtime."
foo-present-p))
#+end_src

this is cumbersome, and there ought to be a way to mitigate the pain, a
macro like

ensure-compile-time-features (&rest features)

which would record whether a feaure is present when the file is being
compiled, and then subsequently arrange to check if the feature was
present at runtime and signal an error if the feature was absent.

Now I think this can be done, but i had to dig in the past for the
compile time value.

There was a thread in February 2008 "Re: passing values from
compile-time to load-time" initiated by SDS which you can probably find
by searching for ABAZONK. I posted a solution on that thread (note to
sds: your followup solution which tried to eliminate the global variable
does not work on any lisp except clisp. the global variable should be
totally harmless and should not be a concern)

here it is from <m3d4qw515z.fsf @robolove.meer.net> cleaned up

#+begin_src
(defvar *compile-time-value-definer* nil
"For internal only. Used by DEFCTV. At the top level this should
always be bound to NIL." )

(defmacro defctv (var expr &optional default)
"Like DEFVAR but defines a \"compile time value\". EXPR is evaluated
at only at compile time. VAR is bound to the result (from the
evaluation of EXPR when the defctv form is compiled) or to DEFAULT if
there is was no compilation."
`(progn
(defvar ,var ,default)
(setq *compile-time-value-definer* nil)
(eval-when (:compile-toplevel)
(setq *compile-time-value-definer*
`(setq ,',var ',(eval ',expr))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(macrolet ((define-compile-time-value ()
*compile-time-value-definer*))
(eval-when (:load-toplevel :execute)
(define-compile-time-value))))))
#+end_src

[Has anyone invented and published defctv in the intervening 12 years?]
Now I can define

#+begin_src
(defmacro require-compile-time-features-at-run-time (&rest features)
"Ensure that the listed that were present (or absent) at compile
time are also present (or absent) at run time."
(dolist (feat features) (check-type feat keyword))
(let ((var (gensym)))
`(progn
(defctv ,var (read-from-string (format nil "(~{#+~(~a~) t ~:*#-~(~a~) nil~^ ~})" ',features)))
(eval-when (load eval)
(let ((mismatches
(loop for ctv in ,var
for feat in ',features
unless (eq ctv (and (find feat *features*) t))
append (list feat ctv))))
(assert (endp mismatches) nil
"~{~(~s~) was ~:[absent~;present~] at compile time but is ~:*~:[present~;absent~] at runtime.~^~%~}" mismatches))))))
#+end_src

Any loopholes? Or can anyone suggest a better name?

Re: name? ensure compile time features are present or absent at runtime

<suimsu$22l$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16866&group=comp.lang.lisp#16866

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: name? ensure compile time features are present or absent
at runtime
Date: Wed, 16 Feb 2022 11:24:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <suimsu$22l$1@dont-email.me>
References: <m37d9v51ik.fsf@leonis4.robolove.meer.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Feb 2022 11:24:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="54e13aad1758c4185ce71dde4cb64a12";
logging-data="2133"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QAJTF84mBIxc1jcsL+ris9zkKM8GqRc4="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:CRsFNL2XAfBN96vTBtjSD+HQbbA=
sha1:UqC3oORU66LGvjuQuJ5MC3BfgnQ=
 by: Zyni Moë - Wed, 16 Feb 2022 11:24 UTC

Madhu <enometh@meer.net> wrote:

>
> Any loopholes? Or can anyone suggest a better name?
>

I have a thing which I stole (borrowed may be) which lets you say

(ensuring-features
((:compile-toplevel :load-toplevel)
(and f1 f2 ...)
f3
(or f4 f5))
(<other time, t means 'all times'>
... more feature expressions ...))

It just expands into suitable eval-whens, and calls to a featurep function
which implements the rules of #+ etc. Obviously it can not do read-time
things, but it can make boolean assertions about what features must exist
at various points. It can not carry things from compile to load time
however.

--
the small snake

Re: name? ensure compile time features are present or absent at runtime

<m3ilt6lzs0.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16918&group=comp.lang.lisp#16918

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: name? ensure compile time features are present or absent at runtime
Date: Wed, 23 Feb 2022 14:34:31 +0530
Organization: Motzarella
Lines: 77
Message-ID: <m3ilt6lzs0.fsf@leonis4.robolove.meer.net>
References: <m37d9v51ik.fsf@leonis4.robolove.meer.net>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="2a977ca0f13b2ef81194382f418a0667";
logging-data="14275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TOP8l2drevdqoGOhl+bHqYpdcCZFqCOw="
Cancel-Lock: sha1:qgEf0X4nZN1bEEBEtR0Vq5yVM0M=
sha1:dWygmpV54rclna+86Jw7b03o7fo=
 by: Madhu - Wed, 23 Feb 2022 09:04 UTC

* Madhu <m37d9v51ik.fsf@leonis4.robolove.meer.net> :
Wrote on Wed, 16 Feb 2022 01:46:19 +0530:

> There was a thread in February 2008 "Re: passing values from
> compile-time to load-time" initiated by SDS which you can probably
> find by searching for ABAZONK. I posted a solution on that thread
> (note to sds: your followup solution which tried to eliminate the
> global variable does not work on any lisp except clisp. the global
> variable should be totally harmless and should not be a concern)

Turns out the code I exhibited here fails *only* on clisp

> here it is from <m3d4qw515z.fsf @robolove.meer.net> cleaned up
>
> #+begin_src lisp
> (defvar *compile-time-value-definer* nil
> "For internal only. Used by DEFCTV. At the top level this should
> always be bound to NIL." )
>
> (defmacro defctv (var expr &optional default)
> "Like DEFVAR but defines a \"compile time value\". EXPR is evaluated
> at only at compile time. VAR is bound to the result (from the
> evaluation of EXPR when the defctv form is compiled) or to DEFAULT if
> there is was no compilation."
> `(progn
> (defvar ,var ,default)
> (setq *compile-time-value-definer* nil)
> (eval-when (:compile-toplevel)
> (setq *compile-time-value-definer*
> `(setq ,',var ',(eval ',expr))))
> (eval-when (:compile-toplevel :load-toplevel :execute)
> (macrolet ((define-compile-time-value ()
> *compile-time-value-definer*))
> (eval-when (:load-toplevel :execute)
> (define-compile-time-value))))))
> #+end_src
>
> #+begin_src lisp
> (defmacro require-compile-time-features-at-run-time (&rest features)
> "Ensure that the listed that were present (or absent) at compile
> time are also present (or absent) at run time."
> (dolist (feat features) (check-type feat keyword))
> (let ((var (gensym)))

I'm using an uninterned gensym for the defctv which goes on to be
defined via defvar. In the code below I expect it to be the same
identical symbol both in compiled and executed phases in the expansion
for defctv (posted above)

It fails on CLISP and I need a
(let ((var (intern (symbol-name (gensym)))))
here.

> `(progn
> (defctv ,var (read-from-string (format nil "(~{#+~(~a~) t ~:*#-~(~a~) nil~^ ~})" ',features)))

VAR expands in DEFCTV to this form at compile time:

`(setq ,',var ',(eval ',expr))

Does this form prohibit VAR from being unintered? Is clisp justified in
throwing an error here?

> (eval-when (load eval)
> (let ((mismatches
> (loop for ctv in ,var
> for feat in ',features
> unless (eq ctv (and (find feat *features*) t))
> append (list feat ctv))))
> (assert (endp mismatches) nil
> "~{~(~s~) was ~:[absent~;present~] at compile time but is ~:*~:[present~;absent~] at runtime.~^~%~}" mismatches))))))
> #+end_src
>
> Any loopholes? Or can anyone suggest a better name?


devel / comp.lang.lisp / name? ensure compile time features are present or absent at runtime

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor