From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Amirouche Boubekki Newsgroups: gmane.lisp.guile.user Subject: Re: How to get started in guile & programming generally Date: Mon, 27 Aug 2018 20:46:10 +0200 Message-ID: References: <87tvnijriu.fsf@fastmail.com> <5ad744d6fb4f61924bd357b727d01421@hypermove.net> <87mut9uh6x.fsf@fastmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1535395780 22934 195.159.176.226 (27 Aug 2018 18:49:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 27 Aug 2018 18:49:40 +0000 (UTC) User-Agent: Roundcube Webmail/1.1.2 Cc: guile-user@gnu.org, guile-user To: Joshua Branson Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Aug 27 20:49:36 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fuMZx-0005pI-IH for guile-user@m.gmane.org; Mon, 27 Aug 2018 20:49:33 +0200 Original-Received: from localhost ([::1]:34746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuMc3-0001Bv-MC for guile-user@m.gmane.org; Mon, 27 Aug 2018 14:51:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuMbl-0001Bp-44 for guile-user@gnu.org; Mon, 27 Aug 2018 14:51:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuMbh-0002L1-60 for guile-user@gnu.org; Mon, 27 Aug 2018 14:51:24 -0400 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:54161) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fuMWl-0002Wh-Id; Mon, 27 Aug 2018 14:46:15 -0400 Original-Received: from webmail.gandi.net (webmail1.sd4.0x35.net [10.200.201.1]) (Authenticated sender: amirouche@hypermove.net) by relay7-d.mail.gandi.net (Postfix) with ESMTPA id C993020003; Mon, 27 Aug 2018 18:46:10 +0000 (UTC) In-Reply-To: <87mut9uh6x.fsf@fastmail.com> X-Sender: amirouche@hypermove.net X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.70.183.200 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14786 Archived-At: On 2018-08-26 20:16, Joshua Branson wrote: > Amirouche Boubekki writes: > >> On 2018-08-25 19:16, Joshua Branson wrote: >>> >> >> You can play with Guile without much C knowledge and I dare to say >> that you >> need little of C with things like guile-bytestructures or nyacc's >> ffi-helper >> to use the full power of GNU Guile. > > Can you elaborate on guile-bytestructures and nyacc's ffi-helper? To get started, with guile foreign function interface [0]. You can dynamically load shared libraries .so files and access its content as pointers. You can convert pointers to scheme procedures or bytevectors. Playing with function pointers as procedures is very easy and is demonstrated in the manual page in dynamic ffi [0]. [0] https://www.gnu.org/software/guile/manual/html_node/Dynamic-FFI.html Playing with bytevectors ie. memory region ie. struct ie. arrays is another story. That's where guile-bytestructures comes in. With guile-bytestructures you can describe the layout of a memory region aka. a struct and they access that struct from guile. guile-bytestructures supports struct, arrays, function pointers, unions and packing! Basically guile-bytestructures allows to represent and manipulate C struct in Scheme. A good live example of using guile-bytestructures is https://gitlab.com/guile-git/guile-git Here is another more recent example (ie. that SHOULD have learned from previous mistake) use of guile-bytestructures. It's not packaged in guix yet. It's way more simpler that guile-git bindings because it only has to deal with structures and there is not memory management or other weird stuff to do. Look into guile-sqlite for a simple use of ffi. Or gnunet-guile2 https://gnunet.org/git/gnunet-guile2.git/tree/gnunet.scm or guile-gdbm. nyacc ffi-helper is built on top of a C parser written in guile and guile-bytestrucutres. The process to build a binding library in guile (and in most languages) is to take the C header file with .h extension associated with the shared library and go through everything that is defined in that file and code in Scheme the glue that is required to access and manipulate them. This is OK task for simple libraries like function-only libraries that manipulates basic data types like string, integers. But for more complicated libraries it's rather painful and more importantly it's a task that is very repetitive. That's why nyacc ffi-helper was created. nyacc ffi helper will read header files and write a guile scheme module glue code that will help in the process of creating bindings. I imagine that in some cases you only need that glue code to have _good_ Guile bindings. Beware that I did not try recently nyacc ffi-helper. The maintainer of nyacc did several demos of getting it working. I believe it requires more love and use. That's why I write about it. If you show enough interest I might create a self contained example use of guile-bytestructures (and nyacc ffi helper). > Is that a recommended/portable way to use guile to call C functions? guile-bytestructures is reported to be portable across scheme implementation, but I only used it on GNU/Linux with Guile. Yes, I recommend the use of guile-bytestructures when it makes sens ie. when you have to deal with C structures. It's not in Guile stdlib because I don't know why. Most recent bindings make use of it. >>> Is there a programming resource for >>> userspace/kernel software >> >> what do you mean by kernel software? > > My short term goal right now is to be able to write GNU/Hurd > translators > in guile. My long term goal is to be a GNU/Hurd developer. Sorry, I don't know what is a GNU/Hurd translators. > >> >>> as good as w3schools.com? >> >> You might not be aware that w3schools has a bad reputation of being >> "loosy". That said I find it >> convenient as quick and dirty reference. I recommend to check mozilla >> developer network aka. mdn >> when it comes to web stuff. > > What do you mean by "loosy?" Sorry, I just repeated what I read elsewhere. What I should have said is that w3cshools is not the only source of information regarding web. But say, for instance, its xpath tutorials are nice. Nowdays I use MDN more often than w3cschools. >> What do you want to make? > > It would be cool to help work on an official GNU distro, using a kernel > that is NOT linux. Linux is cool and good, but I'm not a fan of its > monolithic nature. > Monolitihc has its advantages whatever you think monolith means. See for instance, this convo and article https://news.ycombinator.com/item?id=17499137 I can not stop you from looking into Hurd, but I can not help you. Maybe try hurd mailing list or guix-help. See you around!