AccelerationNet / access

A common lisp library to unify access to common dictionary-like data-structures
Other
84 stars 11 forks source link

access key and function name collision #22

Open Junker opened 1 month ago

Junker commented 1 month ago

In some situations, when an access key has the same name as a function, unexpected behaviour occurs.

Example.

CL-USER> (DEFVAR V1 '(:A 1 :B 2 :SORT "desc"))
V1
CL-USER> (ACCESS:WITH-DOT () 'V1.A)
(ACCESS:ACCESSES V1 'A)
CL-USER> (ACCESS:ACCESSES V1 'A)
1
CL-USER> (ACCESS:ACCESSES V1 'SORT)

invalid number of arguments: 1
   [Condition of type SB-INT:SIMPLE-PROGRAM-ERROR]

Restarts:
 0: [REPLACE-FUNCTION] Call a different function with the same arguments
 1: [CALL-FORM] Call a different form
 2: [RETRY] Retry SLIME REPL evaluation request.
 3: [*ABORT] Return to SLIME's top level.
 4: [ABORT] abort thread (#<THREAD tid=1620761 "repl-thread" RUNNING {1002000003}>)

Backtrace:
  0: (SORT (:A 1 :B 2 :SORT "desc")) [external]
  1: (ACCESS:CALL-IF-APPLICABLE (:A 1 :B 2 :SORT "desc") #<FUNCTION SORT> :WARN-IF-NOT-A-FN? NIL)
  2: (ACCESS:ACCESS (:A 1 :B 2 :SORT "desc") SORT :TYPE NIL :TEST NIL :KEY NIL :SKIP-CALL? NIL)
  3: (ACCESS:ACCESSES #<unavailable argument> SORT)
  4: (SB-INT:SIMPLE-EVAL-IN-LEXENV (ACCESS:ACCESSES V1 (QUOTE SORT)) #<NULL-LEXENV>)
  5: (EVAL (ACCESS:ACCESSES V1 (QUOTE SORT)))
 --more--

This happens because the SORT function exists and is being called. I noticed that the ACCESS function has a SKIP-CALL? key, but it is not accessible from the ACCESSES function or with dot-syntax. Maybe should add SKIP-CALL? key in the ACCESSES and WITH-DOT functions etc.

vindarel commented 1 month ago

Hi, it works if you use a :keyword and not a 'symbol to access the key:

(ACCESS:ACCESSES V1 :SORT)
;; => "desc"

best,

Junker commented 3 weeks ago

thanks for the solution for ACCESSES, but it doesn't solve problem with dot-syntax.

vindarel commented 3 weeks ago

could you explain or showcase what's the problem with the dot syntax?