IRC channel logs

2022-09-22.log

back to list of logs

***iyzsong-alt is now known as iyzsong
<jpoiret>attila_lendvai: for extended examples you might want to check Guix's (guix inferior) or (gnu installer utils)'s "run-external-command-with-handler"
<attila_lendvai>jpoiret, thank you!
<jpoiret>there are some gotchas when using non standard fds for the stdin and stdout, see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52835
<attila_lendvai>jpoiret, your fixes in that bug report... they will not affect the guile interface, right? (except for fixing misbehavior)
<jpoiret>"fixing misbehavior" == affecting the guile interface, no?
<attila_lendvai>yeah, bad wording. i wanted to say API.
<jpoiret>well, technically not, yeah. The last patchset does change the API a bit though
<jpoiret>since spawning a child process can now raise system exceptions, whereas in the past it only returned the pid of the child
<attila_lendvai>jpoiret, you mean the exceptions instead of return codes, right? that's managable. i just don't want to invest a lot into learning pipes in scheme right before a potential major API overhaul... :)
<jpoiret>if that's what you're worried about, don't worry then, no major change
<jpoiret>attila_lendvai: funnily enough, this is what just popped into my inbox https://lwn.net/SubscriberLink/908268/548f97aeaaaa84e5/
<civodul>posix_spawn FTW!
<civodul>the io_uring thing is smart
<civodul>though IIUC correctly, it's like posix_spawn: the interface offers a predefined set of setup operations one can do before exec, right?
<jpoiret>yes, i'd love to see where it goes
<jpoiret>yes, but io_uring could offer a way bigger api
<jpoiret>it's not portable though :(
<civodul>cool
<Trashlord>hi
<Trashlord>kreyren?
<kreyren> http://ix.io/4b6C Running this code results in the wrong formatting where it strips the `--` from `--work-tree=` -> Howddya fix tht
<jpoiret>you don't have a format specifier in your format string
<sneek>tohoyn: Greetings
<kreyren>jpoiret, eh?
<kreyren>the #f is format specifier no?
<jpoiret>no, it says you want format to return the value of the format result
<kreyren>fwiw i tried append-string before with same result
<kreyren>oh
<kreyren>so like `(format #f ~a "--work-tree="...` ?
<jpoiret>the signature is (format PORT-OR-BOOL FORMAT-STRING ARGS ...)
<jpoiret>no, (format #f "--work-tree=~a" repository)
<kreyren>error: unknown option `work-tree=/home/kreyren/Repositories/guix/automation/..'
<kreyren>still
<jpoiret>are you sure work-tree is an option for git checkout?
<kreyren>oh
<kreyren>it's option for `git`, seems to work now thanks ^-^
<M6piz7wk[m]>ping
***M6piz7wk[m] is now known as KREYREN
<wingo>moo
<dthompson>woof
<civodul>meow
<KREYREN>nya nya~
<KREYREN>furries are using guile now eh?
<KREYREN>if so teach them how to submit 50 patches to guix and then merge my patches at https://issues.guix.gnu.org/search?query=author%3Akreyren+tag%3Apatch+is%3Aopen
<dsmith-work>{appropriate time} Greetings, Guilers
<KREYREN>o.o
<KREYREN>Howddya make a loop that runs twice and sets the variable `variable` on USERNAME and TOKEN?
<KREYREN>(when (empty? (getenv variable)
<KREYREN> (format #t "Required variable '~a' is not defined" variable)
<KREYREN> make-undefine-variable-error))
<drakonis>have you considered recursion or using do?
<KREYREN>i looked at https://www.gnu.org/software/guile/manual/html_node/while-do.html and didn't figure out how to make `do` work for me and recursion didn't consider
<KREYREN>the recursion way sounds more fun and potentially nicer code though
*KREYREN is noob in guile
<taw10>Why does it have to run twice?
<flatwhatson>KREYREN: (for-each (lambda (variable) <your code here>) '("USERNAME" "TOKEN"))
<flatwhatson>but you're better off making your code into a function, say (define (get-variable variable) <your code here>)
<KREYREN>taw10: to check if both variables (USERNAME and TOKEN) are set
<KREYREN>flatwhatson: thanks ^-^
<flatwhatson>make it return the value from the variable (use a let to capture the return of getenv and return it afterwards)
<flatwhatson>then your code could be something like (let ((username (get-variable "USERNAME")) (token (get-variable "TOKEN"))) ...)
<KREYREN><flatwhatson> "make it return the value from..." <- why is that beneficial?
<KREYREN>also these variables are designed to be publicly available instead of within a scope
*KREYREN figured out http://ix.io/4b7O
<KREYREN>hmm the two `define` are ugly
<rekado>why do you define them at all when you aren’t using them?
<rekado>also: no need for defines when you can use let.
<KREYREN>rekado: my scripting brain tells me to do sanity check to make sure that they are available and use them later
<rekado>but you’re not using the defined values.
<KREYREN>rekado: so you think something like this instead?
<KREYREN> http://ix.io/4b7R
<KREYREN>or like what? x.x the abstract is get USERNAME and TOKEN from env variable and then do `git checkout upstream`, `git pull`, `git push https://$USERNAME:$TOKEN@git.dotya.ml/kreyren/guix-kreyren.git`
<KREYREN>so that it's a guile script that can be used in the CI/CD
<KREYREN>referencing https://git.dotya.ml/kreyren/guix-kreyren/pulls/2/files
<rekado>like this: https://elephly.net/paste/1663858263.html
<rekado>so pretty much what flatwhatson wrote above
<rekado>BTW: append-string doesn’t exist; it’s called string-append
<KREYREN>oh
<KREYREN>thanku
<KREYREN>why is that wrapped in (define) when it's expected to run immediately
<KREYREN>-> strip the define?
<rekado>no difference; define first run later, or run right away — your call
<KREYREN>hm O.o
<KREYREN>why `error`? It's expected to exit
<rekado>what do you think error does?
<KREYREN>shows error message and then lets the fatal error cause chaos
<KREYREN>oh it shows message and exists
<KREYREN>*exits
<KREYREN>cool
<KREYREN>rekado: btw. you marked the two `load`s as ugly.. is there a non-ugly way?
<KREYREN>beyond using recursion that avoids the duplicate code
<rekado>use modules instead
<KREYREN>you can use modules for local things? O.o
<rekado>I don’t understand the question
<rekado>modules are how you organize code in Guile.
<rekado>local/remote doesn’t factor in it.
<KREYREN>those two files are part of the local repository https://git.dotya.ml/kreyren/guix-kreyren/src/branch/pull-mirror-4-upstream/automation
<KREYREN>hotfixes.scm - compensation for the lack of implementation in guile-git library until that is addressed
<KREYREN>common.scm - things used across all other scripts
<rekado>turn them into modules, then import them
<rekado>this also gives you much more flexibility in terms of where files are located
<rekado>as long as the modules are on the load path they can be used
<rekado>no need for this relative file lookup business
<KREYREN>turn them into modules how? like define libraries with that functionality_
<KREYREN>hm O.o
<KREYREN>for them to be in the load path they would have to be in GUILE_LOAD_PATH env variable right
<rekado>I suggest looking at the Guile Reference manual
<rekado>in your info reader: i define-module RET
<KREYREN>that's what i am doing this whole time >_< https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html
<KREYREN>doesn't say anything useful
<KREYREN>oh define-module
<KREYREN>checking
<KREYREN>rekado: eh? what am i supposed to see on that? O.o
<KREYREN>also the common.scm currently has only the `(define %repodir (string-append (dirname (current-filename)) "/.."))`
<rekado>your info reader will jump to “Creating Guile Modules”, which is a good starting point if you want to learn how to define modules and all that.
<KREYREN>i know how to define modules but i don't understand the beneficial usecase
<tricon>KREYREN: you aren't dependent upon relative load paths. it's good practice to isolate contexts, domains, etc. into modules.
<KREYREN>hm O.o
<KREYREN>and the only way to use those modules is using GUILE_LOAD_PATH right
*KREYREN goes to figure out the implementation then
<tricon>KREYREN: GUILE_LOAD_PATH or, if invoking manually, ~guile -L path-to-modules file.scm~
<KREYREN>o.o
<KREYREN> http://ix.io/4b8y
<KREYREN>ehh how do i get the let things as input to the procedure?
<KREYREN>like i figured out that i can get rid of the parenthesis in the definition but that will also get rid of the docstring
<rekado>you can pass anything to a procedure as long as it binds variables
<rekado>(lambda (foo bar baz . rest) …) binds three arguments to the variables “foo”, “bar”, and “baz”, and whatever else is passed to it is bound to the variable “rest”.
<rekado>(define whatever (lambda …)) is binding the procedure to the name “whatever”
<rekado>that’s the same as (define (whatever foo bar baz . rest) …)
<rekado>if you don’t want to use positional arguments search the manual for keyword arguments
<KREYREN>o.o
<KREYREN>thanks checking
<KREYREN>What is the prettier way to write (when (= variable "") ...) ?
<KREYREN>like negation of empty?
<rekado>(string-null? variable)
<KREYREN>i meant if it's not null -> #t
<KREYREN>... i wrote the example code wrong my bad >_<
<rekado>(negate string-null?)
<rekado>or use match
<KREYREN>o.o i guess that works thanks
<rekado>but getenv returns #f when the variable is not set
<KREYREN>i don't use getenv for this >_>
<KREYREN>was hoping `non-empty?` would be a thing
<rekado>(define non-empty (negate string-null?))
<rekado>it’s probably not a good idea to use the empty string when you can use a different value
<KREYREN>o.o
<KREYREN>rekado: FWIW figured out this atm http://ix.io/4b9n
<rekado>you can also use “unless” instead of “when”
<rekado>(unless (string-null? forge) …)
<KREYREN>oh
<KREYREN>thanku
<rekado>I wouldn’t use #:optional with #:key
<KREYREN>what would you use to achieve the optional pushing?
<rekado>#:key (forge #t) is just fine
<KREYREN>oh right O.o
<rekado>it will be #t unless set to something else
<rekado>and what’s up with “nil”?
<rekado>nil is not a Scheme value
<KREYREN>oh what's the alternative to like unset variable then?
*KREYREN is confusing it with common lisp probably
<rekado>by default an unspecified keyword argument will be #false
<KREYREN>so doing like (source-repo #f) ?
<KREYREN>assuming that `empty?` will work on it
<rekado>what’s “empty?”?
<KREYREN>like doing (when (empty? source-repo) (error "..."))
<rekado>(define* (meh #:key foo bar baz) …) accepts three optional keyword arguments. If they are not specified they are #f.
<KREYREN>to sanitize the inputs
<KREYREN>oh
<rekado>you can also give them an error expression as the default value
<rekado>(define* (meh #:key (foo (error "foo is required"))) …)
<KREYREN>cool
<KREYREN>can i combine? like (define* (meh #:key (foo bar) baz) ?
<rekado>that would make “bar” the default value for “foo” if it isn’t specified when calling “meh”.
<KREYREN>bar being defaul value for foo is expected, but i don't know if it's sane to expect baz to be #f ?
<rekado>if you don’t provide a default value the default will always be #f
<KREYREN>good good