This is a minor complaint. Why can't one use nil to match an empty list?

Consider the following:

(deffacts init
  (sprocket 1 spacely)
  (sprocket 2))

(defrule non-nil-match
  (sprocket ?id ?name&~nil $?)
  =>
  (printout t "sprocket " ?id " is named " ?name "." crlf))

(defrule nil-match-1st-try
  (sprocket ?id nil $?)
  =>
  (printout t "sprocket " ?id " is unnamed (1st try)." crlf))

(defrule nil-match-2nd-try
  (sprocket ?id nil)
  =>
  (printout t "sprocket " ?id " is unnamed (2nd try)." crlf))

(defrule nil-match-3rd-try
  (sprocket ?id)
  =>
  (printout t "sprocket " ?id " is unnamed (3rd try)." crlf))

Running this program results in:

Jess> (run)
sprocket 2 is unnamed (3rd try).
sprocket 1 is named spacely.
3
Jess>

Only the pattern (sprocket ?id) matches (sprocket 2) with no following
symbols. I would have thought that (sprocket ?id nil) at least would
also work, i.e. nil matching the empty list, especially considering that
~~nil matches a non-null symbol. Perhaps my concept of nil is influenced
too much by Lisp.

Thanks,

-Steve Solomon


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to