suppose I have c code of:
[1] foo *bar = get_foo(); [2] if (bar != NULL) { ... }
in scheme, I have
(let ((bar (get-foo))) [1] [2] <-- how do I write this line in scheme?
thanks!
Afficher les réponses par date
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
lowly coder wrote:
suppose I have c code of:
[1] foo *bar = get_foo(); [2] if (bar != NULL) { ... }
in scheme, I have
(let ((bar (get-foo))) [1] [2] <-- how do I write this line in scheme?
(if bar (do-something-with bar) (do-something-else))
(get-foo) should evaluate to #f if there is no bar.
You should give #scheme a try for such basic questions.
Good luck,
Marijn
- -- Sarcasm puts the iron in irony, cynicism the steel.
Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML http://www.gentoo.org/proj/en/lisp/, #gentoo-{lisp,ml} on FreeNode
it works now; thanks!
the main reason I posted to gambit rather than #scheme ... is that this seems a C-FFI (thus implementation specific question, not a generic scheme question)
if I'm wrong ... please point out what scheme standard defines how NULLS from C-FFI/land is handled in scheme?
On Sat, Feb 14, 2009 at 2:26 PM, Marijn Schouten (hkBst) hkBst@gentoo.orgwrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
lowly coder wrote:
suppose I have c code of:
[1] foo *bar = get_foo(); [2] if (bar != NULL) { ... }
in scheme, I have
(let ((bar (get-foo))) [1] [2] <-- how do I write this line in scheme?
(if bar (do-something-with bar) (do-something-else))
(get-foo) should evaluate to #f if there is no bar.
You should give #scheme a try for such basic questions.
Good luck,
Marijn
Sarcasm puts the iron in irony, cynicism the steel.
Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML http://www.gentoo.org/proj/en/lisp/, #gentoo-{lisp,ml} on FreeNode -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkmXRSkACgkQp/VmCx0OL2xTLwCfQFdraxstZxU626l8wj7Fzmit MB0AoLkb48VNsPl3QZHdiKZqVIwG5aVy =s+QO -----END PGP SIGNATURE-----
If `get-foo' is an FFI and returns an object created in that foreign environment, then perhaps it's better if you keep any predicates related such objects in that foreign environment as well. Then just implement the appropriate FFIs in gambit.
Pavel
On Sat, Feb 14, 2009 at 2:32 PM, lowly coder lowlycoder@huoyanjinjing.com wrote:
it works now; thanks!
the main reason I posted to gambit rather than #scheme ... is that this seems a C-FFI (thus implementation specific question, not a generic scheme question)
if I'm wrong ... please point out what scheme standard defines how NULLS from C-FFI/land is handled in scheme?
On Sat, Feb 14, 2009 at 2:26 PM, Marijn Schouten (hkBst) hkBst@gentoo.org wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
lowly coder wrote:
suppose I have c code of:
[1] foo *bar = get_foo(); [2] if (bar != NULL) { ... }
in scheme, I have
(let ((bar (get-foo))) [1] [2] <-- how do I write this line in scheme?
(if bar (do-something-with bar) (do-something-else))
(get-foo) should evaluate to #f if there is no bar.
You should give #scheme a try for such basic questions.
Good luck,
Marijn
Sarcasm puts the iron in irony, cynicism the steel.
Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML http://www.gentoo.org/proj/en/lisp/, #gentoo-{lisp,ml} on FreeNode -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkmXRSkACgkQp/VmCx0OL2xTLwCfQFdraxstZxU626l8wj7Fzmit MB0AoLkb48VNsPl3QZHdiKZqVIwG5aVy =s+QO -----END PGP SIGNATURE-----
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 14-Feb-09, at 5:32 PM, lowly coder wrote:
it works now; thanks!
the main reason I posted to gambit rather than #scheme ... is that this seems a C-FFI (thus implementation specific question, not a generic scheme question)
if I'm wrong ... please point out what scheme standard defines how NULLS from C-FFI/land is handled in scheme?
If you define get-foo this way
(define get-foo (c-lambda () (pointer foo) "get_foo"))
then the C NULL maps to the Scheme #f. On the other hand, if you want to exclude the possibility that the pointer is NULL then define it this way
(define get-foo (c-lambda () (nonnull-pointer foo) "get_foo"))
These are Gambit specific things.
Marc