Re: Using "internal" macros of a CL implementation



Ken Tilton <kentilton@xxxxxxxxx> writes:

Victor Kryukov wrote:
Hello group,

I've the following question: I want to define macro case-string, which
behaves exactly like case, only using string-equal instead of eql.

I've looked up definition of case in SBCL[*], and realized that my
task is as simple as

(defmacro case-string (keyform &body cases)
(case-body 'case keyform cases t 'string-equal nil nil nil))

COND.

Let me be more precise here. I do understand how to use COND to
achieve what I need. I just want more useful macro, so that

(let ((keyform "test"))
(case-string keyform
("test1" 'test1)
(("test2" "test3") 'test2-or-3)
(("test" "test4") 'test-or-4)))

would evaluate to TEST-OR-4. Of course, you can do that simply by
using COND, as Ken suggested:

(cond
((string= keyform "test1") 'test1)
((member keyform '("test2" "test3") :test #'string=) 'test2-or-3)
((member keyform '("test" "test4") :test #'string=) 'test-or-4))

and is seems not that hard to write case-string macro which translates
first snippet to the second. I've just noticed that similar
functionality already existed in SBCL core - e.g. case is really
similar, it's only uses 'eql instead of string=, and is defined with
help of internal macro case-body; my question was how one can possibly
access such macros (even in non-portable way) to avoid duplicating
existing functionality.

Victor.
.



Relevant Pages

  • Re: Using "internal" macros of a CL implementation
    ... I want to define macro case-string, ... (defmacro case-string (keyform &body cases) ... ((string= keyform "test1") ... Access to a symbol in a package is made by package:symbol, or package::symbol if it is not exported. ...
    (comp.lang.lisp)
  • Compile-time text/string manipulation
    ... A "compile-time language" is one that processes ... Compile time languages for assemblers ... This group includes macro ... requires access to various string and text manipulation ...
    (alt.lang.asm)
  • RE: Search email for text string to use in filename - save email t
    ... The code for my macro is below. ... .MatchWholeWord = False ... Dim sNewFileName As String ... > 0 Then Exit Function ...
    (microsoft.public.outlook.program_vba)
  • Re: Document Property to display more than 1 line
    ... then use the following macro to identify the character ... Dim strNums As String ...
    (microsoft.public.word.newusers)
  • Re: Form refresh code
    ... Your version of the InserrtAddress macro also unlocked the field with the ... string variable name in the protect/unprotect commands. ... Public Sub InsertAddressFromOutlook() ... Dim strCode As String, strAddress As String ...
    (microsoft.public.word.docmanagement)