Subject: Re: [bug#28251] [PATCH 1/3] packages: Add package->code.

From: Ricardo Wurmus <[email-masked]>
Date: Thu, 28 Sep 2017 13:19:21 +0200

Ludovic Courtès <[email-masked]> writes:

> Ricardo Wurmus <[email-masked]> skribis:
>
>> * guix/packages.scm (package->code): New procedure.
>
> We’ll need tests for this.  :-)

I’ve added some simple tests to tests/print.scm and import-utils.scm.

> I would move it to (guix import utils) or a new (guix import print)
> module or similar (which will also allow us to use ‘factorize-uri’).  In
> my mind, eventually all importers will produce a <package> object
> directly, and so this will be a core part of the import machinery.
> Since it’s not a crucial component, I would prefer to have it out of
> (guix packages) though.

Okay, done.

>> +;; FIXME: the quasiquoted arguments field may contain embedded package
>> +;; objects, e.g. in #:disallowed-references; they will just be printed with
>> +;; their usual #<package ...> representation, not as variable names.
>
> Not sure how to solve that; maybe we can ignore for now.

That’s why I originally experimented with overriding the printer.  For
the purposes of a JSON importer, however, this really isn’t important.

>> +(define (package->code package)
>> +  "Return an S-expression representing the source code that produces PACKAGE
>> +when evaluated."
>
> Like you wrote, it would be nice to also return a spec of modules in
> scope, like:
>
>   ((gnu packages r)
>    ((guix licenses) #:prefix license:))
>
> WDYT?

I’ll leave this as a later improvement, but yes: I’ll add this at some
point.

> I think we should compare values with ‘eq?’ (usually we’re concerned
> with pointer identity of records), and also use ‘module-for-each’ +
> ‘let/ec’ to avoid building a list for nothing

That’s good!

> Nitpick: I’d rename all the ‘print-*’ procedures to ‘*->code’.

Done.

I’ve implemented the other suggested changes and added some
documentation.  I’ll push it to master in a few minutes.

Thanks for the comments!

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net