G-Golf - Getting started
Hi G-Golfers, >From here: https://www.gnu.org/software/g-golf/manual/g-golf.html GNU G-Golf can be obtained from the following archive site http://ftp.gnu.org/gnu/g-golf/. The file will be named g-golf-version.tar.gz. The current version is 0.1.0, so the file you should grab is: http://ftp.gnu.org/gnu/g-golf/g-golf-0.1.0.tar.gz This directory does not exist. So I used the git repo, built and installed. I extracted the hello-world example (attached) $ guile -s example-1.scm # takes about 7 seconds guile -s example-1.scm Backtrace: 8 (apply-smob/1 #) In ice-9/boot-9.scm: 705:2 7 (call-with-prompt _ _ #) In ice-9/eval.scm: 619:8 6 (_ #(#(#))) In ice-9/boot-9.scm: 2312:4 5 (save-module-excursion _) 3832:12 4 (_) In g-golf/hl-api/function.scm: 140:19 3 (_ . _) In unknown file: 2 (_ # # 3 …) In g-golf/hl-api/closure.scm: 255:8 1 (g-closure-marshal _ _ _ _ _ _) In /home/paule/Projects/coot/git/g-golf/build/example-1.scm: 14:4 0 (activate _) /home/paule/Projects/coot/git/g-golf/build/example-1.scm:14:4: In procedure activate: In procedure module-lookup: Unbound variable: set-child Have I done something wrong? Thanks, Paul. ;; Load Gtk (use-modules (g-golf)) (gi-import "Gtk") ;; When the application is launched.. (define (activate app) ;; - Create a new window and a new button (let ((window (make #:title "Hello" #:application app)) (button (make #:label "Hello, World!"))) ;; - Which closes the window when clicked (connect button 'clicked (lambda (b) (close window))) (set-child window button) (show window))) (let ((app (make #:application-id "com.example.GtkApplication"))) (connect app 'activate activate) (run app 0 '()))
Re: G-Golf - Getting started
Hi Paul On Mon, Apr 12, 2021 at 12:35:58PM +0100, Paul Emsley wrote: > Hi G-Golfers, > > >From here: > https://www.gnu.org/software/g-golf/manual/g-golf.html > > >GNU G-Golf can be obtained from the following archive site > http://ftp.gnu.org/gnu/g-golf/. The file will >be named g-golf-version.tar.gz. The current version is 0.1.0, so the file > you should grab is: > > http://ftp.gnu.org/gnu/g-golf/g-golf-0.1.0.tar.gz > > This directory does not exist. > > So I used the git repo, built and installed. I extracted the hello-world > example (attached) > > $ guile -s example-1.scm # takes about 7 seconds > guile -s example-1.scm > Backtrace: >8 (apply-smob/1 #) > In ice-9/boot-9.scm: > 705:2 7 (call-with-prompt _ _ #) > In ice-9/eval.scm: > 619:8 6 (_ #(#(#))) > In ice-9/boot-9.scm: >2312:4 5 (save-module-excursion _) > 3832:12 4 (_) > In g-golf/hl-api/function.scm: >140:19 3 (_ . _) > In unknown file: >2 (_ # # 3 …) > In g-golf/hl-api/closure.scm: > 255:8 1 (g-closure-marshal _ _ _ _ _ _) > In /home/paule/Projects/coot/git/g-golf/build/example-1.scm: > 14:4 0 (activate _) > > /home/paule/Projects/coot/git/g-golf/build/example-1.scm:14:4: In procedure > activate: > In procedure module-lookup: Unbound variable: set-child > > Have I done something wrong? No, git-grep tells me there is no 'set-child' function in the g-golf repository. I've modified the example and it now works as expected, see below: 8< ;; Load Gtk (use-modules (g-golf)) (gi-import "Gtk") ;; When the application is launched.. (define (activate app) ;; - Create a new window and a new button (let ((window (make #:title "Hello" #:application app)) (button-box (make )) (button (make #:label "Hello, World!"))) ;; - Which closes the window when clicked (connect button 'clicked (lambda (b) (close window))) (gtk-container-add window button-box) (gtk-container-add button-box button) (show button) (show button-box) (show window))) (let ((app (make #:application-id "com.example.GtkApplication"))) (connect app 'activate activate) (run app 0 '())) >8 HTH, Vladimir
Guile AWS
Hi Guilers, this is not quite a release announcement, but the code turns out to be usable enough that I thought I’d share what I’ve got at this point. Guile AWS is a library that lets you talk to Amazon Web Services such as S3, the Elastic Compute Cloud (EC2), Elastic File System (EFS), Route53 (Amazon’s DNS server), etc. The implementation is probably more interesting than the library itself. Guile AWS is little more than a language specification for the Guile compiler tower, which compiles the JSON specification of the AWS APIs to Scheme. There’s also a bit of inelegant plumbing to actually make requests to an API endpoint. I’ve been hacking on this library on and off again, testing only those bits that I needed, so I would be happy if others were to play with it and/or improve it. Here’s what a session might look like: --8<---cut here---start->8--- (import (aws api elasticfilesystem-2015-02-01)) ;; You can also use the parameters %aws-default-region, %aws-access-key, ;; and %aws-secret-access-key (setenv "AWS_DEFAULT_REGION" "eu-central-1") (setenv "AWS_SECRET_ACCESS_KEY" "…") (setenv "AWS_ACCESS_KEY_ID" "AKIA…") ;; Create a file system with this unique creation token. (CreateFileSystem #:CreationToken "my-guile-aws-filesystem" #:Tags (list (Tag #:Key "project" #:Value "guile-aws") (Tag #:Key "type" #:Value "test"))) ;; => returns some JSON, including the fs-id … (import (aws api ec2-2016-11-15)) (RunInstances #:MaxCount 1 #:MinCount 1 #:ImageId %my-ami #:KeyName %my-ssh-key-name #:SubnetId %my-subnet-id #:InstanceType type #:InstanceInitiatedShutdownBehavior "terminate" #:BlockDeviceMappings (list (BlockDeviceMapping #:DeviceName "/dev/xvda" #:Ebs (EbsBlockDevice #:DeleteOnTermination #true #:VolumeType "gp3" #:VolumeSize 2)) (BlockDeviceMapping #:DeviceName "/dev/sdf" #:Ebs (EbsBlockDevice #:DeleteOnTermination #true #:SnapshotId "snapshot-whatever" #:VolumeType "gp3" #:Iops 6000))) #:TagSpecifications (list (TagSpecification #:ResourceType "instance" #:Tags (list (Tag #:Key "created-by" #:Value "guile-aws") (Tag #:Key "name" #:Value "guile-aws-test" #:SecurityGroupIds %my-security-groups #:UserData %encoded-userdata) ;; => returns some SXML response --8<---cut here---end--->8--- The biggest flaw in Guile AWS is handling of responses. Currently, the responses are raw JSON or SXML (dependent on the API protocol). I left it this way because I found that converting the response to an opaque record type just isn’t very nice; it made processing of responses quite a bit harder. If you have a good idea how to best represent the responses in a more Schemey way, please do let me know! Another open issue is plumbing. A conversation with AWS APIs is reminiscent of monadic computations (in that computations can fail at any point and the flow should not be burdened with error handling), and it also feels like prompts and delimited continuations would be a good fit. Currently, there is nothing here to simplify a conversation with the API, e.g. to repeat API calls until a certain condition is met, to time out requests or to abort polling after n retries, or even to just handle errors. The biggest obstacle was the variability in AWS APIs. Some expect XML payloads, others JSON, yet others expect a weirdly mangled request string (some sort of custom stringy representation of the request payload) — it’s a zoo! I’m still pretty sure that there are a bunch of ridiculous bugs in the code, and it’s difficult for me to come up with good tests. I’d appreciate any help! Having said all that: this really works for my limited use cases. I can create EC2 instances, initialize them, tag them, terminate them, attach volumes, create and configure EFS file systems, attach them, update DNS records for newly generated machines, etc. The code is here: https://git.elephly.net/gitweb.cgi?p=software/guile-aws.git and here’s a Guix package definition: --8<---cut here---start->8--- (use-modules ((guix licenses) #:prefix license:) (guix packages) (guix git-download) (guix utils) (guix build-system gnu) (gnu packages) (gnu packages autotools) (gnu packages databases)
Re: [EXT] Guile AWS
On Mon, Apr 12, 2021 at 11:48 AM Ricardo Wurmus wrote: > > Hi Guilers, > > this is not quite a release announcement, but the code turns out to be > usable enough that I thought I’d share what I’ve got at this point. > > Guile AWS is a library that lets you talk to Amazon Web Services such as > S3, the Elastic Compute Cloud (EC2), Elastic File System (EFS), Route53 > (Amazon’s DNS server), etc. The implementation is probably more > interesting than the library itself. > > Guile AWS is little more than a language specification for the Guile > compiler tower, which compiles the JSON specification of the AWS APIs to > Scheme. There’s also a bit of inelegant plumbing to actually make > requests to an API endpoint. Hell yeah, this rules! Years ago I took the same approach to generate a Guile API for CloudFormation (an unreleased experiment) and was hoping that someone would do the same for the entire AWS API. As far as error handling goes, the official AWS SDK for NodeJS may be something to study. It uses asyncs (which is a syntax over simple promises) to allow for threading together multiple API requests together and handle errors without too much headache. Most of the time I use the Ruby SDK, less often the Python SDK (boto3), and in both you just have to catch exceptions or inspect responses yourself, so if that's what you have to do with the guile-aws for the time being then you're still on par with several official SDKs. Those SDKs don't do anything magical with the responses, either, so I consider being given a big ol' deserialized json/xml response in the form of a compound s-exp to be just fine. - Dave
Re: G-Golf - Getting started
Hello Paul, > From here: > https://www.gnu.org/software/g-golf/manual/g-golf.html There is no G-Golf release yet - it is mentioned on the web-site, both the home page and in the install page ... but not in the manual indeed, didn't want to ... > $ guile -s example-1.scm # takes about 7 seconds > guile -s example-1.scm Please read the Getting Started with G-Golf, Selective Import ... you are importing the entire Gtk namespace - here, fwiw, if I do that, it takes 2sec, so mileage varies depending on the machine, mem ... > Backtrace: > ... > /home/paule/Projects/coot/git/g-golf/build/example-1.scm:14:4: In > procedure activate: In procedure module-lookup: Unbound variable: > set-child > Have I done something wrong? Yes :) you copied and run an example which is for Gtk-4.0, but loading Gtk-3.0 ... In the manual, 'Getting Started with G-Golf': "Please note that in the entire course of the G-Golf manual, unless otherwise specified, examples are based on and use Gtk-4.0, Gdk-4.0 and Gsk-4.0 - which is new and only available with Gtk-4.0." Below, an example for Gtk-3.0 ... David ;; below, ;; a hello-world example for GTk-3.0 #! /bin/sh # -*- mode: scheme; coding: utf-8 -*- exec guile -e main -s "$0" "$@" !# (eval-when (expand load eval) (use-modules (oop goops)) (default-duplicate-binding-handler '(merge-generics replace warn-override-core warn last)) (use-modules (g-golf)) (for-each (lambda (name) (gi-import-by-name "Gtk" name #:version "3.0")) '("Application" "ApplicationWindow" "Box" "Label" "Button"))) (define (activate app) (let ((window (make #:title "Hello" #:default-width 320 #:default-height 240 #:application app)) (box(make #:margin-top 6 #:margin-start 12 #:margin-bottom 6 #:margin-end 6 #:orientation 'vertical)) (label (make #:label "Hello, World!")) (button (make #:label "Close"))) (connect button 'clicked (lambda (b) (close window))) (add window box) (pack-start box label #t #t 0) (pack-start box button #f #f 6) (show-all window))) (define (main args) (let ((app (make #:application-id "org.gnu.tests"))) (connect app 'activate activate) (run app (length args) args))) pgpkTbHLQqu3d.pgp Description: OpenPGP digital signature
Re: [EXT] Guile AWS
Thompson, David writes: > Years ago I took the same approach to generate a Guile API for > CloudFormation (an unreleased experiment) and was hoping that someone > would do the same for the entire AWS API. Your CloudFormation experiment was indeed the spark that ignited the fire. Guile AWS isn’t based on your code, but I learned a lot from looking at it a few years back, and it planted the seed to implement Guile AWS using the same approach. > As far as error handling goes, the official AWS SDK for NodeJS may be > something to study. It uses asyncs (which is a syntax over simple > promises) to allow for threading together multiple API requests > together and handle errors without too much headache. Most of the time > I use the Ruby SDK, less often the Python SDK (boto3), and in both you > just have to catch exceptions or inspect responses yourself, so if > that's what you have to do with the guile-aws for the time being then > you're still on par with several official SDKs. Those SDKs don't do > anything magical with the responses, either, so I consider being given > a big ol' deserialized json/xml response in the form of a compound > s-exp to be just fine. Ah, that’s good to know. Still, I think at the very least guile-aws ought to present a unified data structure — either an alist, a JSON expression, or some SXML, but not a different structure dependent on whatever the API uses internally. -- Ricardo