This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GSOC | Extending Common Lisp support


On Jun 9, 2012, at 10:55 AM, Charles Turner wrote:

I've attached some bits and pieces related to my work so far with
packages. It's all very raw and nonconforming in lots of different
ways. It "works" in the trivial sense that I can create new package
and move into them, but I haven't yet tested symbol resolution much,
other than writing a SYMBOL-PACKAGE function, that current check the
symbol's namesace, and if that's empty returns the value of *PACKAGE*.

Seems reasonable so far.


One problem I'm having with thread locations is their return value of
#!null. Is there a clean way of having it by default return nil that
anyone knows of? Not actually sure if I should be using a thread
location, but it might be useful to be able to specify a default
package on the command line, like we do in the pretty printer with
out:print-circle.

It *seems* like that's the purpose of defaultValue in get(Object defaultValue), right? Except that the default value is ignored:

#|kawa:1|# (define q-loc ::gnu.mapping.ThreadLocation (gnu.mapping.ThreadLocation "q"))
#|kawa:2|# (q-loc:get #f)
#!null
#|kawa:3|# (q-loc:get)
#!null


I dug through it a bit and saw that ThreadLocation#get(Object) defers
to the implementation in SharedLocation:

  public synchronized final Object get (Object defaultValue)
  {
    return base != null ? base.get(defaultValue)
      : value == Location.UNBOUND ? defaultValue : value;
  }

That says the default is only used if value==Location.UNBOUND. But guess what:
value (declared in IndirectableLocation) is initialized to null, not
Location.UNBOUND -- instantiating a ThreadLocation effectively defines its
value to be null.


So the only way to have our defaultValue returned is to set
value:=Location.UNBOUND first.

Looks like IndirectableLocation#undefine might do the trick. Let's see:

#|kawa:4|# (q-loc:undefine)
#|kawa:5|# (q-loc:get 't)
#!null

Hmm. Oh, right, gotta do it on the wrapped NamedLocation. (Is that a
bug or a feature?)

#|kawa:6|# ((q-loc:get-location):undefine)
#|kawa:7|# (q-loc:get 't)
t
#|kawa:8|# (q-loc:get #f)
#f
#|kawa:9|# (q-loc:get ())
()
#|kawa:10|# (q-loc:get)
unbound location q (property (dynamic))
at gnu.mapping.Location.get(Location.java:67)
at atInteractiveLevel$10.run(stdin:10)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:299)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:200)
at kawa.Shell.run(Shell.java:279)
at kawa.Shell.run(Shell.java:194)
at kawa.Shell.run(Shell.java:175)
at kawa.repl.main(repl.java:891)
#|kawa:11|# *print-right-margin*
#!null
#|kawa:12|# (gnu.text.PrettyWriter:lineLengthLoc:get)
#!null
#|kawa:13|# (gnu.text.PrettyWriter:lineLengthLoc:set 5)
#|kawa:14|# *print-right-margin*
5
#|kawa:15|# ((gnu.text.PrettyWriter:lineLengthLoc:get- location):undefine)
#|kawa:16|# *print-right-margin*
<unknown>: warning - no declaration seen for *print-right-margin*
unbound location *print-right-margin*
at gnu.mapping.Location.get(Location.java:67)
at atInteractiveLevel$16.run(stdin)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:299)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:200)
at kawa.Shell.run(Shell.java:279)
at kawa.Shell.run(Shell.java:194)
at kawa.Shell.run(Shell.java:175)
at kawa.repl.main(repl.java:891)



OK, it would appear that evaluating *print-right-margin* is like invoking get() and not get(default). Depending upon what you want to do with your ThreadLocation, maybe that's fine, or maybe you should just call set(NIL) early on.


-- Jamison Hope The PTR Group www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]