chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] ANN: eping


From: Michele La Monaca
Subject: Re: [Chicken-users] ANN: eping
Date: Thu, 22 Aug 2013 14:42:54 +0200

How can I check if a symbol is bound to a value?

I would like to do this:

(define host "example.com")

(eping host)      ; host is evaluated
(eping localhost) ; localhost is treated as a symbol

with a macro like that:

(define-syntax eping
  (syntax-rules ()
    ((_ h)
     (if (and (symbol? 'h) (bound? 'h))
       (_eping h)
       (_eping (symbol->string '|h|))))))


Trying to evaluate the symbol seems to be an option:

(handle-exceptions exn-unbound
  (set! host (symbol->string '|h|))
  (eval 'h)
  (set! host h))

but maybe there's a better way.

On Thu, Aug 22, 2013 at 12:24 PM, Michele La Monaca
<address@hidden> wrote:
> Forget the previous macro. Hopefully this one will do the intended job.
>
> (define-syntax eping
>   (syntax-rules ()
>     ((_ h)
>      (_eping (symbol->string '|h|)))
>     ((_ h p1 p2 ...) (_eping (symbol->string '|h|) 'p1 p2 ...))))
>
>
> On Thu, Aug 22, 2013 at 11:29 AM, Michele La Monaca
> <address@hidden> wrote:
>> On Wed, Jun 26, 2013 at 2:22 PM, John Cowan <address@hidden> wrote:
>>> Michele La Monaca scripsit:
>>>
>>>> Happy pinging.
>>>
>>> Cool!
>>>
>>> I made a minor documentation change on the wiki to encourage strings over
>>> symbols as hostnames, and to remove the suggestion to use dotted-decimal
>>> symbols like '192.168.1.1.  Such a symbol violates both R5RS and R7RS,
>>> is not portable, and might stop working some day.  (You could write it as
>>> '|192.168.1.1|, but that is more verbose than the string form.)
>>
>> What about redefining eping as a macro to call the real eping function 
>> (_eping)?
>>
>> (define-syntax eping
>>   (syntax-rules ()
>>     ((_ h p ...) (_eping (symbol->string '|h|) 'p ...))))
>>
>> This way you can simply:
>>
>> (eping 192.168.1.1)
>>
>> or
>>
>> (eping example.com)
>>
>> Thoughts?
>>
>> Ciao,
>> Michele



reply via email to

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