|
From: | Pan Xie |
Subject: | Re: Question about how to check a symbol is bound |
Date: | Fri, 23 Jun 2023 16:01:40 +0800 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 |
#+begin_quote Perhaps if you can explain why you need to know if a symbol is bound or unbound, we might be able to help you better achieve your goal. #+end_quote For example, if I want to do things shown in following codes, it is useful to get the interned symbols from their names and also get their bound procedures: (define-record egg-info name author desc)(define (show-egg-info egg)
(define (symbol-value sym) (##sys#slot sym 0))(define (getter field-name)
(symbol-value (string->symbol (format #f "egg-info-~a" field-name))))(let ((fields '(name author desc)))
(for-each (lambda (f) (format #t "~a: ~a~%" f ((getter f) egg))) fields))) (show-egg-info (make-egg-info "F-operator" "Kon Lovett" "Shift/Reset Control Operators")) I think it is a very common idiom in languages from Lisp family. So it is important to know how to check symbol is bound and get its value. Every scheme implementation means for business seriously should have the ability. Thanks Pan On 6/23/23 15:40, Peter Bex wrote:
On Fri, Jun 23, 2023 at 03:32:38PM +0800, Pan wrote:Ah, that make sense. It seems I can just use the '##sys#slot' procedure to accomplish all that tasks.Please don't use ##sys#slot unless you know what you're doing - the procedure is unsafe and will cause segmentation faults when used on non-block objects. Anything that starts with ##sys# or ##core# etc is intentionally undocumented because it's not meant for user code.Would you please elaborate about the "transformed name"? I see there are codes reference symbols like "##sys#slot" or "scheme#list", but I can't find document describe them. Is there any document I can look into? More specifically, how can I transfer "list" to "scheme#list"? Is there procedure can do that?scheme#list is the fully qualified symbol that means it's the "list" procedure from the "scheme" module. If you do "(import scheme)" and then just use "list" without prefix, it will get rewritten under the hood. Again, this is an implementation detail and not meant to be used directly. Perhaps if you can explain why you need to know if a symbol is bound or unbound, we might be able to help you better achieve your goal. Cheers, Peter
[Prev in Thread] | Current Thread | [Next in Thread] |