kawa-commonlisp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Kawa-commonlisp-dev] 'NIL != '()


From: Per Bothner
Subject: Re: [Kawa-commonlisp-dev] 'NIL != '()
Date: Tue, 07 Aug 2012 16:06:15 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0

On 08/07/2012 03:15 PM, Jamison Hope wrote:

The initialisation in CommonLisp:

 public static final LList FALSE = LList.Empty;
 public static final Expression nilExpr = new QuoteExp(FALSE);

seems to point to the problem, obviously they were designed to be
different objects, which seems wrong to me, but this is code Per
wrote, so I'm not confident I understand what's happening here.

Any suggestions on how to fix this?

Those are separate objects because one is a value (one you are likely
to encounter from user code) and the other is an Expression which is
internal to the workings of the compiler.

Correct.

In particular, nilExpr is not 'nil:

But it should be.

The inequality between 'nil and '() is a completely separate issue.
Note:

#|kawa:1|# ()
()
#|kawa:2|# '()
()
#|kawa:3|# nil
()
#|kawa:4|# 'nil
nil
#|kawa:5|# (eval 'nil)
()

These should all be the same: CommonLisp.FALSE.

Whether this value *prints* as () or nil (or NIL)
might depend on printer settings, but that is a separate issue.

Other CL implementations probably get away with this by just using the symbol
itself as the canonical representation of NIL; Kawa, however, chooses to use
LList.Empty so that Scheme lists and Lisp lists are interchangeable.

One could argue it should be the otherwise; I'm not sure what is best.

However, as long as things are the way the are, the reader does need to
special case nil. Basically nil is first resolved to COMMON-LISP:NIL.
But then "at the last minute" we replace the result by CommonLisp.FALSE.

Something like, using your repository code:

      Object s = LispPackage.currentPackage.get().intern(symname).get(0);
      if (s == CommonLisp.NIL_AS_SYMBOL)
        s = CommonLisp.FALSE:
      return s;

where CommonLisp.NIL_AS_SYMBOL is CommonLispPackage.getSymbol("NIL").

For things like property-list access on the symbol 'nil (which I'm
not sure if is allowed) use CommonLisp.NIL_AS_SYMBOL.

For example (symbol-plist sym) needs to do something like:

(define (symbol-plist symbol)
 (gnu.mapping.PropertyLocation:getPropertyList
    (if (eq symbol CommonLisp:FALSE) CommonLisp:NIL_AS_SYMBOL symbol)))

The helper method gnu.commonlisp.lang.Symbol.getSymbol does something similar.
Perhaps we need this method:

  public static Symbol asSymbol(Object sym)
  {
return sym == CommonLisp.FALSE ? CommonLisp.NIL_AS_SYMBOL : (Symbol) sym;
  }

--
        --Per Bothner
address@hidden   http://per.bothner.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]