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

Discussion of Common Lisp
Post Reply
garethw
Posts: 43
Joined: Fri Jul 13, 2012 12:56 pm
Location: Ottawa, ON

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

Post by garethw » Tue Feb 02, 2016 9:52 pm

Hi all,

Given some structure, say:

Code: Select all

(defstruct quux
  name)
is the following a "literal"?

Code: Select all

#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:

Code: Select all

`(#S(quux :name "Guy"))
=>
"unrecognized object in quasiquote"
and in poking around, the expansion code includes a call to FARE-UTILS:LITERALP, which is:

Code: Select all

(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

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

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

Post by Goheeca » Wed Feb 03, 2016 4:15 am

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.

pjstirling
Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

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

Post by pjstirling » Wed Feb 03, 2016 9:02 am

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

garethw
Posts: 43
Joined: Fri Jul 13, 2012 12:56 pm
Location: Ottawa, ON

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

Post by garethw » Wed Feb 03, 2016 12:04 pm

Goheeca wrote:Can you describe what SBCL is doing? I have right now installed pretty old version 1.1.12.
It returns =>

Code: Select all

(#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:

Code: Select all

`(#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

garethw
Posts: 43
Joined: Fri Jul 13, 2012 12:56 pm
Location: Ottawa, ON

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

Post by garethw » Thu Feb 04, 2016 8:09 am

FWIW, Fare agreed this is likely a bug.

Thanks for your help, Goheeca and pjstirling.
~garethw

marcoxa
Posts: 85
Joined: Thu Aug 14, 2008 6:31 pm

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

Post by marcoxa » Tue Feb 09, 2016 7:35 am

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

Cheers
--
MA
Marco Antoniotti

Post Reply