chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Re: Updated objc-header.scm


From: Zbigniew
Subject: [Chicken-users] Re: Updated objc-header.scm
Date: Tue, 13 Jun 2006 15:11:00 -0500

If you want to use your existing structure without the namespace
pollution, here is a possible solution, minus user-friendly error
messages.  Change the name munging as desired.

#;1> (use objc)

;; Add clause to prepend objc: to first element of list, throw this in
objc-header.scm
#;2>
(define (macro:type->encoding x)
 (cond ((symbol? x) (string->symbol
                     (string-append "objc:" (symbol->string x))))
       ((list? x)
        (cons (string->symbol
               (string-append "objc:" (symbol->string (car x))))
              (cdr x)))
       (else x)))

;; (gen-ID NSString) -> macro (objc:NSString*)
#;3>
(define-macro (gen-ID TYPE)
        `(define-macro (,(string->symbol (conc "objc:" TYPE "*")))
                'objc:ID))

#;4> (gen-ID NSString)
#;5> (objc:NSString*)
"@"
#;6> (define-objc-class ABCD NSObject () (+ (NSString*) hello (print
"hi") "booga"))
#;7> (@ ABCD hello)
hi
@"booga"


On 6/13/06, Kon Lovett <address@hidden> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Jun 13, 2006, at 12:31 PM, Zbigniew wrote:

> Kon,
>
> I've been away for a bit and am just now catching up on my email
> backlog.  It looks like a interesting idea.  However, I'm curious why
> you made NSString* and so on into macros that generate 'objc:ID etc.,
> instead of using variables.  In other words:
>
> #;2> (define objc:NSString* objc:ID)
> #;3> (define-objc-class ABCD NSObject ()
>              (+ NSString* hello
>                  (print "hi")
>                  "ooga"))
> #;4> (@ ABCD hello)
> hi
> @"ooga"
> #;5>
>
> Is this approach workable?  Do you want the extra parens to emulate
> the look of Objective C, or find the macros are necessary?

Emulate the look of obj-c. Variables are fine too.

   (- NSData* ((#:dataOfType NSString* aType) (#:error NSError**
outerr))

>
> As an aside, the function macro:type->encoding provides some control
> over this conversion; the default behaviour---prepend objc: to
> symbols, pass the rest through---allows you to evaluate functions or
> pass encoded typestrings directly.  It is possible to augment this to
> provide alternate syntax, for example when you pass a list; your
> macros do effectively the same job, with just a bit of namespace
> pollution.

In practice, a lot of namespace pollution. The set I defined is
popular but a real app would have lots of these things. Some other
method is preferable.

>
> The only qualm I have about allowing type-like symbols instead of
> plain ID and PTR is that it gives the erroneous impression of
> typechecking, whereas ID and PTR spell this out.  I guess it comes
> down to user preference and, ultimately, can be loaded if the user so
> desires.

I wanted them to remind me what was coming in & going out,
documentation really.




reply via email to

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