unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Using in C a function defined in guile
@ 2015-09-06 14:10 Vladimir Zhbanov
  2015-09-06 14:54 ` Taylan Ulrich Bayırlı/Kammer
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Vladimir Zhbanov @ 2015-09-06 14:10 UTC (permalink / raw)
  To: guile-user

Hi, guilers.

After speaking with a man who doesn't like scheme and wants to make all
his work in C, I wonder if there is an easy way to make the procedures
wholly written in Guile available in C, besides any kind of 'eval'.
Looking through the guile info I didn't found anything other.

Thanks,
  Vladimir



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 14:10 Using in C a function defined in guile Vladimir Zhbanov
@ 2015-09-06 14:54 ` Taylan Ulrich Bayırlı/Kammer
  2015-09-06 15:23 ` Panicz Maciej Godek
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2015-09-06 14:54 UTC (permalink / raw)
  To: guile-user

Vladimir Zhbanov <vzhbanov@gmail.com> writes:

> Hi, guilers.
>
> After speaking with a man who doesn't like scheme and wants to make all
> his work in C, I wonder if there is an easy way to make the procedures
> wholly written in Guile available in C, besides any kind of 'eval'.
> Looking through the guile info I didn't found anything other.

You might want to look into the Dynamic FFI section of the Guile Info
manual: (info "(guile) Dynamic FFI")

Web version:
http://www.gnu.org/software/guile/manual/html_node/Dynamic-FFI.html

In summary, you can get pointers to Guile procedures via
'procedure->pointer' ('scm_procedure_to_pointer' in the C API).

Working with complicated struct types might be somewhat uncomfortable,
and I'm working on https://github.com/taylanub/scheme-bytestructures to
solve that, but I haven't worked on integrating it with the FFI much
yet.  On the meanwhile there's (info "(guile) Foreign Structs").

Web:
http://www.gnu.org/software/guile/manual/html_node/Foreign-Structs.html

You might also want to go through the rest of the FFI chapter of the
manual to see if there's anything useful for you:
(info "(guile) Foreign Function Interface")

Web:
http://www.gnu.org/software/guile/manual/html_node/Foreign-Function-Interface.html

> Thanks,
>   Vladimir

That's my limited knowledge.
Hope it helps,
Taylan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 14:10 Using in C a function defined in guile Vladimir Zhbanov
  2015-09-06 14:54 ` Taylan Ulrich Bayırlı/Kammer
@ 2015-09-06 15:23 ` Panicz Maciej Godek
  2015-09-06 18:52   ` Vladimir Zhbanov
  2015-09-06 16:09 ` Mike Gran
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Panicz Maciej Godek @ 2015-09-06 15:23 UTC (permalink / raw)
  To: guile-user@gnu.org, vzhbanov

[-- Attachment #1: Type: text/plain, Size: 639 bytes --]

2015-09-06 16:10 GMT+02:00 Vladimir Zhbanov <vzhbanov@gmail.com>:

> Hi, guilers.
>
> After speaking with a man who doesn't like scheme and wants to make all
> his work in C, I wonder if there is an easy way to make the procedures
> wholly written in Guile available in C, besides any kind of 'eval'.
> Looking through the guile info I didn't found anything other


This is because this is contrary to the intended use of Guile (which
focuses on having C procedures available in Scheme rather than other way
around).

I think that you may take a look at something that compiles Scheme code to
C, like Gambit, Chicken, Scheme->C or Stalin.

[-- Attachment #2: Type: text/html, Size: 1111 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 14:10 Using in C a function defined in guile Vladimir Zhbanov
  2015-09-06 14:54 ` Taylan Ulrich Bayırlı/Kammer
  2015-09-06 15:23 ` Panicz Maciej Godek
@ 2015-09-06 16:09 ` Mike Gran
  2015-09-06 16:37   ` Arne Babenhauserheide
  2015-09-06 19:44   ` Vladimir Zhbanov
  2015-09-06 16:21 ` Arne Babenhauserheide
  2015-09-06 17:09 ` David Kastrup
  4 siblings, 2 replies; 10+ messages in thread
From: Mike Gran @ 2015-09-06 16:09 UTC (permalink / raw)
  To: Vladimir Zhbanov, guile-user@gnu.org


On Sunday, September 6, 2015 7:10 AM, Vladimir Zhbanov <vzhbanov@gmail.com> wrote:


>
>
>Hi, guilers.
>
>After speaking with a man who doesn't like scheme and wants to make all
>his work in C, I wonder if there is an easy way to make the procedures
>wholly written in Guile available in C, besides any kind of 'eval'.
>Looking through the guile info I didn't found anything other.

The simplest way to implement such a thing is using
functions like scm_c_eval_string, where one creates a string
containing Guile code and executes it.

There are more complicated strategies that might be slightly faster.
One could get a variable that contains a procedure by using
scm_c_public_lookup.  Then, the procedure itself can be extracted
by using scm_variable_ref.  And it can be called using
The scm_call_0, scm_call_1 family of functions.

There is an example in the manual here
http://www.gnu.org/software/guile/manual/html_node/Accessing-Modules-from-C.html

-Mike



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 14:10 Using in C a function defined in guile Vladimir Zhbanov
                   ` (2 preceding siblings ...)
  2015-09-06 16:09 ` Mike Gran
@ 2015-09-06 16:21 ` Arne Babenhauserheide
  2015-09-06 19:39   ` Vladimir Zhbanov
  2015-09-06 17:09 ` David Kastrup
  4 siblings, 1 reply; 10+ messages in thread
From: Arne Babenhauserheide @ 2015-09-06 16:21 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Hi Vadimir,

Am Sonntag, 6. September 2015, 17:10:01 schrieb Vladimir Zhbanov:
> After speaking with a man who doesn't like scheme and wants to make all
> his work in C, I wonder if there is an easy way to make the procedures
> wholly written in Guile available in C, besides any kind of 'eval'.
> Looking through the guile info I didn't found anything other.

The manual shows how to call Guile functions from your program:
http://www.gnu.org/software/guile/manual/guile.html#Guile-Initialization-Functions

The sample however embeds a full Guile shell:
http://www.gnu.org/software/guile/manual/guile.html#A-Sample-Guile-Main-Program

If I recall correctly, if you only want to provide the Scheme
functions, stick to scm_init_guile and scm_with_guile.

See Initializing Guile from the API reference:
http://www.gnu.org/software/guile/manual/guile.html#Initialization

Best wishes,
Arne

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 299 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 16:09 ` Mike Gran
@ 2015-09-06 16:37   ` Arne Babenhauserheide
  2015-09-06 19:44   ` Vladimir Zhbanov
  1 sibling, 0 replies; 10+ messages in thread
From: Arne Babenhauserheide @ 2015-09-06 16:37 UTC (permalink / raw)
  To: guile-user, Mike Gran

[-- Attachment #1: Type: text/plain, Size: 467 bytes --]

Am Sonntag, 6. September 2015, 16:09:06 schrieb Mike Gran:
> The simplest way to implement such a thing is using
> functions like scm_c_eval_string, where one creates a string
> containing Guile code and executes it.
> …
> There is an example in the manual here
> http://www.gnu.org/software/guile/manual/html_node/Accessing-Modules-from-C.html

That’s much better than what I wrote. Please don’t let yourself get stuck on my mail.

Best wishes,
Arne

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 299 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 14:10 Using in C a function defined in guile Vladimir Zhbanov
                   ` (3 preceding siblings ...)
  2015-09-06 16:21 ` Arne Babenhauserheide
@ 2015-09-06 17:09 ` David Kastrup
  4 siblings, 0 replies; 10+ messages in thread
From: David Kastrup @ 2015-09-06 17:09 UTC (permalink / raw)
  To: guile-user

Vladimir Zhbanov <vzhbanov@gmail.com> writes:

> Hi, guilers.
>
> After speaking with a man who doesn't like scheme and wants to make all
> his work in C, I wonder if there is an easy way to make the procedures
> wholly written in Guile available in C, besides any kind of 'eval'.
> Looking through the guile info I didn't found anything other.

C++ allows for some syntactically nicer techniques.

Cf
<URL:http://git.savannah.gnu.org/cgit/lilypond.git/commit/?id=652f454fae6ed31ced7f9c3ce22dbc5752460a8c>
for an implementation in a large-scale C++/GUILE project.  The
interesting files are those created from scratch in the patch (green in
the diffstat).

-- 
David Kastrup




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 15:23 ` Panicz Maciej Godek
@ 2015-09-06 18:52   ` Vladimir Zhbanov
  0 siblings, 0 replies; 10+ messages in thread
From: Vladimir Zhbanov @ 2015-09-06 18:52 UTC (permalink / raw)
  To: guile-user

On Sun, Sep 06, 2015 at 05:23:38PM +0200, Panicz Maciej Godek wrote:
> 2015-09-06 16:10 GMT+02:00 Vladimir Zhbanov <vzhbanov@gmail.com>:
> 
> > Hi, guilers.
> >
> > After speaking with a man who doesn't like scheme and wants to make all
> > his work in C, I wonder if there is an easy way to make the procedures
> > wholly written in Guile available in C, besides any kind of 'eval'.
> > Looking through the guile info I didn't found anything other
> 
> 
> This is because this is contrary to the intended use of Guile (which
> focuses on having C procedures available in Scheme rather than other way
> around).
> 
> I think that you may take a look at something that compiles Scheme code to
> C, like Gambit, Chicken, Scheme->C or Stalin.

Sorry, I won't use them, the project in question is gEDA and (I hope) it
hardly will use any other Scheme dialect in the near future.

Thanks,
  Vladimir



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 16:21 ` Arne Babenhauserheide
@ 2015-09-06 19:39   ` Vladimir Zhbanov
  0 siblings, 0 replies; 10+ messages in thread
From: Vladimir Zhbanov @ 2015-09-06 19:39 UTC (permalink / raw)
  To: guile-user

On Sun, Sep 06, 2015 at 06:21:35PM +0200, Arne Babenhauserheide wrote:
> Hi Vadimir,
> 
> Am Sonntag, 6. September 2015, 17:10:01 schrieb Vladimir Zhbanov:
> > After speaking with a man who doesn't like scheme and wants to make all
> > his work in C, I wonder if there is an easy way to make the procedures
> > wholly written in Guile available in C, besides any kind of 'eval'.
> > Looking through the guile info I didn't found anything other.
> 
> The manual shows how to call Guile functions from your program:
> http://www.gnu.org/software/guile/manual/guile.html#Guile-Initialization-Functions
> 
> The sample however embeds a full Guile shell:
> http://www.gnu.org/software/guile/manual/guile.html#A-Sample-Guile-Main-Program
> 
> If I recall correctly, if you only want to provide the Scheme
> functions, stick to scm_init_guile and scm_with_guile.
> 
> See Initializing Guile from the API reference:
> http://www.gnu.org/software/guile/manual/guile.html#Initialization

Thank you, Arne.

I've already read all the sections you're referring to here.

Cheers,
  Vladimir



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using in C a function defined in guile
  2015-09-06 16:09 ` Mike Gran
  2015-09-06 16:37   ` Arne Babenhauserheide
@ 2015-09-06 19:44   ` Vladimir Zhbanov
  1 sibling, 0 replies; 10+ messages in thread
From: Vladimir Zhbanov @ 2015-09-06 19:44 UTC (permalink / raw)
  To: guile-user

Mike, thank you!

It seems to be the info I searched for.

Thanks,
  Vladimir



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-09-06 19:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-06 14:10 Using in C a function defined in guile Vladimir Zhbanov
2015-09-06 14:54 ` Taylan Ulrich Bayırlı/Kammer
2015-09-06 15:23 ` Panicz Maciej Godek
2015-09-06 18:52   ` Vladimir Zhbanov
2015-09-06 16:09 ` Mike Gran
2015-09-06 16:37   ` Arne Babenhauserheide
2015-09-06 19:44   ` Vladimir Zhbanov
2015-09-06 16:21 ` Arne Babenhauserheide
2015-09-06 19:39   ` Vladimir Zhbanov
2015-09-06 17:09 ` David Kastrup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).