[email protected] writes:

> I've been stuck for a few days on the following:
> Let's say I have a record type:
>
> (define-record-type* <my-record> my-record make-my-record
>   my-record?
>   this-record
>  (first-field my-record-first-field)
>  (second-field my-record-second-field))
>
> And a function that uses such a record, but needs to run on the build
> side, because it also needs the store path of a package (I can't edit
> this function):
>
> (define (function-of-a-record-and-a-build-time-path rec path)
>   "Concatenate the path, first, and second field"
>   (string-append path " " (my-record-first-field rec) " " (car
>   (my-record-second-field rec)) " " (cdr (my-record-second-field rec))))
>
> How can I use this record in the build side. For example, I'm unable to
> build the following G-exp:
> (define a-record (my-record
>               (first-field "first")
>               (second-field '("second" . "third"))))
>
>
> #~(with-output-to-file (string-append #$output "/file.txt")
>      (lambda _
>        (display (function-of-a-record-and-a-build-time-path #$a-record
>      #$bash)))))

Could you ungexp the record access bits? So something like:

  (string-append #$path " " #$(my-record-first-field rec) " " #$(car
    (my-record-second-field rec)) " " #$(cdr (my-record-second-field
    rec)))

Obviously, then the handling of rec would just be on the build side.

I'm not quite sure quite what your code looks like, in the example you
give, you've got a number of problems.

Ignoring the #$a-record, you'll need to (mkdir #$output) before trying
to write to a file within that directory.

Secondly, function-of-a-record-and-a-build-time-path isn't defined on
the build side.

If you want to define function-of-a-record-and-a-build-time-path on the
host side, then you could have it return a gexp, something like:

  (define (function-of-a-record-and-a-build-time-path rec path)
    "Concatenate the path, first, and second field"
    #~(string-append #$path " " #$(my-record-first-field rec) " " #$(car 
(my-record-second-field rec)) " " #$(cdr (my-record-second-field rec))))

  (build-gexp
   #~(begin
       (mkdir #$output)
       (with-output-to-file (string-append #$output "/file.txt")
         (lambda _
           (display #$(function-of-a-record-and-a-build-time-path  a-record 
bash))))))

With these changes, the example you give works for me.

Attachment: signature.asc
Description: PGP signature

Reply via email to