Anyone to help with .sls/.sld files? Artyom Bologov (30 Aug 2024 13:29 UTC)
Re: Anyone to help with .sls/.sld files? Amirouche (30 Aug 2024 14:32 UTC)
Re: Anyone to help with .sls/.sld files? Lassi Kortela (30 Aug 2024 15:45 UTC)
Re: Anyone to help with .sls/.sld files? Artyom Bologov (30 Aug 2024 18:27 UTC)
Re: Anyone to help with .sls/.sld files? Lassi Kortela (30 Aug 2024 19:29 UTC)
Re: Anyone to help with .sls/.sld files? Lassi Kortela (30 Aug 2024 20:50 UTC)
Re: Anyone to help with .sls/.sld files? Artyom Bologov (31 Aug 2024 00:03 UTC)
Re: Anyone to help with .sls/.sld files? Retropikzel (31 Aug 2024 14:17 UTC)
Re: Anyone to help with .sls/.sld files? Arthur A. Gleckler (31 Aug 2024 16:02 UTC)

Re: Anyone to help with .sls/.sld files? Artyom Bologov 30 Aug 2024 18:27 UTC

Hi Amirouche,

(CC Lassi, scroll down)

> What is the problem with the libraries?

Gambit can't find the library:
> (load "253.sld")
"/home/aartaka/git/srfi-253/srfi/253.sld"
> (import (srfi 253))
*** ERROR IN (stdin)@2.9 -- Cannot find library (srfi 253)

Gerbil complains about syntax:
$ gerbil 253.sld
*** ERROR IN gx#stx-map1 --
*** ERROR IN "253.sld"@26.3-29.31
--- Syntax Error: Bad syntax; illegal expression
... form:   (export check-arg
                    values-checked
                    let-checked
                    lambda-checked
                    define-checked
                    opt-lambda-checked
                    define-optionals-checked
                    case-lambda-checked)
... detail: (%#export check-arg values-checked let-checked lambda-checked define-checked opt-lambda-checked define-optionals-checked case-lambda-checked) at "253.sld"@26.3-29.31

Gauche does not accept rest arguments in macros, but that's a different problem.

Chicken:
$ csi 253.sld
...
Error: unbound variable: define-library

STklos cannot import SRFI-227:
$ stklos -l 253.sld
**** Error while loading file "253.sld"
	 Where: in error
	Reason: bad import clause (srfi 227)

Lots of things, ahah.

> Why test.scm does not import (srfi 253)?

Indeed! I'm sending a pull request with this and other fixes:
https://github.com/scheme-requests-for-implementation/srfi-253/pull/15

>
> By the way, an alternative form of:
>
>   ;; It's possible that there are *no* audio devices available, in
>   ;; which case open-device throws an exception.  In that case, return
>   ;; #f.
>   (let ((device (false-if-exception (openal:open-device))))
>     (and device
>          (%make-sound-system device ...)))
>
> ref: https://github.com/scheme-requests-for-implementation/srfi-253/blob/master/existing-practice.scm#L293
>
> It is possible to use and=> from the builtin guile env, and srfi-26 cut:
>
>   (and=> (false-if-exception (openal:open-device))) (cut (sound-system <> ...)))
>
> ref: https://www.gnu.org/software/guile/manual/html_node/Higher_002dOrder-Functions.html#index-and_003d_003e
>
> In that particular case, it is easier to do:
>
>   (guard (ex (else #f))
>     (sound-system (openal:open-device) ...))
>
> The form and=> is terse, handy, less general form of and-let*:
>
>   (and-let* ((device (false-if-exception ...)) (sound-system (make-sound-system device ...))) sound-system))
>
> ref: https://srfi.schemers.org/srfi-2/

existing-practice.scm is a mishmash of code taken from other codebases
as a way to highlight existing practices. It's not meant to be executed,
it's merely there for illustrative purposes.

Hi Lassi,

> The file names need to be consistent with the library names used in
> the source code. srfi/srfi.sld should be srfi/253.sld
> instead. srfi/srfi.sls is more complicated, as R6RS file naming
> conventions are a mess.

I've seen the :253.sls, but that's breaking Emacs, so I'm not risking
naming it this way. I'll call it 253.sls for now.

> Write (define-library (srfi 253) ...) and (library (srfi :253) ...)
> respectively.

Yes, thanks! I've already compiled a patch!

> Using `export` inside `cond-expand` is an anti-pattern. A library
> should export the same set of identifiers in all cases.

Okay. Let it be this way, even if they end up unbound.

> (cond-expand ... (else)) is probably not appropriate here. It may
> cause an unsupported implementation to silently import the library
> until the user attempts to call one of the non-existent procedures. If
> you leave out the `else` branch, a well-behaved Scheme implementation
> will raise an error at import time.

No, the (else) part makes sense here: implementation-specific files are
extensions over the impl.generic.scm, adding things on top of an
otherwise self-sufficient base library. So the empty (else) is simply
sticking with defaults.

> In (library ...) [i.e. R6RS], (include "...") is non-standard and is
> probably best avoided.

So I should include all the code in the (begin ...) inside library?
That's bad, no wonder many abandon the R6RS-specific library files.
I'll think whether I should too.

Thanks a lot!
--
Artyom Bologov
https://aartaka.me