From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Newbie packagers Date: Thu, 21 Jul 2016 17:52:43 +0200 Message-ID: <87poq7dm44.fsf@elephly.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGHS-000191-T5 for help-guix@gnu.org; Thu, 21 Jul 2016 11:52:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQGHM-0007Ds-Sl for help-guix@gnu.org; Thu, 21 Jul 2016 11:52:57 -0400 Received: from sender163-mail.zoho.com ([74.201.84.163]:24327) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGHM-0007DR-Ix for help-guix@gnu.org; Thu, 21 Jul 2016 11:52:52 -0400 In-reply-to: List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+gcggh-help-guix=m.gmane.org@gnu.org Sender: "Help-Guix" To: Vincent Legoll Cc: help-guix@gnu.org Hi Vincent, > - the comma operator > - the backquote operator > - the quote operator > - the arobase operator (is it for list unpacking ?) These are all about list quoting. This is code: (+ 1 2 3) It evaluates to 6. This is quoted code (aka data): '(+ 1 2 3) It doesn’t get evaluated any further. This is pretty much the same as: `(+ 1 2 3) But with the backtick (called “quasiquote”) you are permitted to temporarily switch from “data mode” to “code mode”. That’s what the comma (“unquote”) does: `(+ 1 2 3 4 ,(+ 3 2) 6) ^ ^ data mode code mode The result is the same as '(+ 1 2 3 4 5 6) What’s nice about this is that we can use the same syntax for code that is to be evaluated right now and for code that we want to pass somewhere else as inert data which will be evaluated at a later point. This allows for “staging”. When you look at a typical package expression you see that the value of the “arguments” field is quoted. It is not evaluated right away but in a second stage. The value of the inputs field is also quoted. You see that we unquote the values of package variables there. Package expressions in Guix are just Scheme values. The inputs field does not merely hold a list of symbols that somehow represent the packages — it actually contains the very values themselves! “,@” is for splicing lists: (let ((moo '(1 2 3))) `(foo bar ,@moo meh)) This binds the list '(1 2 3) to the name “moo” and then splices it into another list. This results in '(foo bar 1 2 3 meh) Without the “@” and just a regular unquote comma it would be a nested list: (let ((moo '(1 2 3))) `(foo bar ,moo meh)) => '(foo bar (1 2 3) meh) Quoting and unquoting is a very useful feature. I hope my explanations above are easy to understand. > - the percent operator That’s no operator. It’s part of the name. We use the percent as a prefix for variables that are “special”, e.g. global variables or values that appear without having to be explicitly let-bound. > - the #: operator These are called keyword arguments. They are no operators either. Using keyword arguments allows you to specify arguments by name, not in some fixed order. > - the different module import things (#:use-module vs (use-modules) vs ...) That’s probably explained in the Guile reference manual. We use “#:use-module” only in module definitions. “(use-modules …)” can be used anywhere else. > I tried to find a good tutorial explaining all of those, but couldn't. I found > snippets that helped me understand some of those, but they were scattered, > and it's still blurry. > > Specific explanations will be more useful that a general scheme tutorial, the > hello.scm is good as an example : > > (inputs `(("gawk" ,gawk))) > > here we use the backquote because ... > the comma is there for ... > > (arguments `(#:configure-flags '("--enable-silent-rules"))) > > here the #: means ... > we use the simple quote because ... Yeah, I agree. There should be a quick crash course. I spent half the day yesterday to introduce all these things to a colleague who will create a few Guix packages in the future. It would be cool to have this as part of the manual. ~~ Ricardo