This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Is #S(quux ...) a literal?

6 posts · 6860 views

Hi all,

Given some structure, say:
(defstruct quux
  name)
is the following a "literal"?
#S(quux :name "Guy")
I ask because I was playing with OPTIMA, and wanted to use FARE-QUASIQUOTE for specifying patterns with backquotes, but FARE-QUASIQUOTE is not pleased:
`(#S(quux :name "Guy"))
=>
"unrecognized object in quasiquote"
and in poking around, the expansion code includes a call to FARE-UTILS:LITERALP, which is:
(defun literalp (x)
  "predicate that tells whether X is the source form for a literal expression."
  (typep x '(or boolean number character array keyword)))
Structures are conspicuously missing, and that surprised me. SBCL's new(ish) backquoting does what I expect. Is this a grey area? Not something one should rely on?
~garethw

Re: Is #S(quux ...) a literal?

Can you describe what SBCL is doing? I have right now installed pretty old version 1.1.12.
Nevertheless, sharpsign syntax denotes a reader macro and that means it is by a standard way evaluated before the quasiquotation takes a place or in other words the quasiquotation doesn't stop evaluating reader macros. Does that FARE-QUASIQUOTE works with complex numbers?
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Re: Is #S(quux ...) a literal?

Yes, for compilation purposes #s(quux :name "Guy") creates a literal object, complain to fare :)

Re: Is #S(quux ...) a literal?

Goheeca wrote:Can you describe what SBCL is doing? I have right now installed pretty old version 1.1.12.
It returns =>
(#S(QUUX :NAME "Guy"))
Goheeca wrote:Nevertheless, sharpsign syntax denotes a reader macro and that means it is by a standard way evaluated before the quasiquotation takes a place or in other words the quasiquotation doesn't stop evaluating reader macros. Does that FARE-QUASIQUOTE works with complex numbers?
Understood. The problem is not in the reader, it's in Fare's expander, which relies on that function to determine if something is a literal, concludes it is not, and falls through the rest of the COND that calls it to that error condition.

F-Q handles complex numbers gracefully as expected:
`(#C(1 2))
=>
(#C(1 2))
pjstirling wrote:Yes, for compilation purposes #s(quux :name "Guy") creates a literal object, complain to fare :)
Done, for (hopefully) humble values of COMPLAIN. Thanks for the confidence boost to do so.
~garethw

Re: Is #S(quux ...) a literal?

FWIW, Fare agreed this is likely a bug.

Thanks for your help, Goheeca and pjstirling.
~garethw

Re: Is #S(quux ...) a literal?

You should play with CL-UNIFICATION (yep; this is a shameless plug).

Cheers
--
MA
Marco Antoniotti