From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.user Subject: Re: Project scheme-python Date: Sat, 19 Sep 2020 22:25:25 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4902"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Sep 19 22:25:53 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJjQe-0001BL-OG for guile-user@m.gmane-mx.org; Sat, 19 Sep 2020 22:25:52 +0200 Original-Received: from localhost ([::1]:51970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJjQd-0001ar-Ps for guile-user@m.gmane-mx.org; Sat, 19 Sep 2020 16:25:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJjQT-0001ae-Pm for guile-user@gnu.org; Sat, 19 Sep 2020 16:25:41 -0400 Original-Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:44785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJjQQ-0004L7-WA for guile-user@gnu.org; Sat, 19 Sep 2020 16:25:41 -0400 Original-Received: by mail-wr1-x42f.google.com with SMTP id s12so8902919wrw.11 for ; Sat, 19 Sep 2020 13:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0QZ0dLeb3Mq9itg6VVHJGyZfT73qjgTXeNW5zN1x0kI=; b=CnnlGsjZ8swvcKV4yaIgSZHJpjxDjt0CPWZnYDHoVFyl46zrjMRnWBo+TPVrcZe2wv yp44PxowqEAXiJ16cruCxOTz46q4JpM2yeD7zrmv02fNklTy35S2t1c5Gdvjs5QjrXnC o/ZQr4KZjnG0KzLWn/yAjuH2GXPleeXB/vvGco8PBH7TGgBmkKEOZP3kii7st6F0I1jK 1mehlAfPduG1Cgu4XmuLKwi5PdfNAPb84TlGU6F0cdOm2Muzrzy3wH82ycg6qzPnwXCn GEglnFxMCplwAnVMujkT5REPl1mfyV+hstzQd1d2uD6A2w+rMcOeHOYfVUly2svqrdcL v5cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0QZ0dLeb3Mq9itg6VVHJGyZfT73qjgTXeNW5zN1x0kI=; b=PKbdFt6GvGkoXMyai2KevGhWx+T7J5WMwF+fLTf1lQZcx2V/66LhglS1UBESAkOA5K rzRvM/dCu6WpqsdQx7B998oAto6URoB6BXaKIX0+gQiwsjnN6PAbzqYF//y+RgR1o9dy LTthRF/qy3MDhh6I6O8nvB+G4YoxERIwY2iUM7Rn4WgFtATHCmI8Td6ofCedCEsXSKd5 7jIVosNXZZPXJaVqjQPkbAk36vC/kAahcwiIgl0EU568ZbWFSRNsAcviDZ0vlhS+bJKy XkJF4/7ZPLWzdXWBGhpUtQKie4tfiIbROtqNe2MPR79nVURWqa987HL4sgGifcGpV6x8 r5qg== X-Gm-Message-State: AOAM5307nF0dMyAFx2ZSszf1cZeqzNAEesucHOPce7+QlhhD7kNoqGEn DB1JaJdWyWph7/I2fLPuk7pTKeuB3PatwYWWGxs= X-Google-Smtp-Source: ABdhPJwYeKYtxF9xDrRoJVVnAJ9/DcDjb6+UK/825jmCcEH6v0W+kZ4I/iDewEAoqEL4WfHCurrS7nRsd20UCkONW4c= X-Received: by 2002:adf:91e1:: with SMTP id 88mr43762623wri.305.1600547136326; Sat, 19 Sep 2020 13:25:36 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=stefan.itampe@gmail.com; helo=mail-wr1-x42f.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16924 Archived-At: Hi, I added a better README with som more guts... Here is some introduction, This Toolset for guile that is a subset of the python-on-guile toolset that is stand alone and does not depend on any other scheme projects then guile itself being installed. go to modules: autoreconf -i ./configure make sudo make install And you are ready to go. For documentation of most of the scheme interface see http://c-lambda.se/python-on-guile/ If you want to have functioning persistence you need to have the guile-persist guile libs installed (https://gitlab.com/tampe/guile-persist). Example: > (use-modules (util scheme-python)) > (define b (bytes "abc")) > b b'abc' ;; we wrap bytevectors and represen= t ;; standardize representing them as ;; latin 1 > (define b (bytearray b)) > (define c b) > (=3D* b 10) > b bytearray(b'abcabcabcabcabcabcabcabcabcabc') > (eq? b c) #t ;; pythons +=3D *=3D is implemented = and for ;; bytesarrays the lhs is modified ;; similar for set operations on set's ;; should be more scalable then usin= g ;; + of * > (define l (py-list '(1 2 3))) > l [1,2,3] > (+ l l) [1,2,3,1,2,3] > (define ll l) > (+=3D l l) > l [1,2,3,1,2,3] > (eq? l ll) #t > (define b (bytes "ab=C3=B6")) ;; defaults to encode using latin= 1 comp ;; (not utf-8 comp) > (py-upper b) b'AB=C3=96' > (define b (bytes "the red fox")) > (py-capitalize b) b'The Red Fox' > (define a (py-set '(1,2))) > (define b (py-set '(2,3))) > (py-logxor a b) set([1,3]) ;; symmetric difference > (py-logior a b) ;; union set([1,2,3]) > (py-logand a b) ;; intersection set([2]) > (- a b) ;; set difference set([1]) > (&=3D a b) ;; intersection with a and put the res= ult ;; in a similarly we hav or=3D ^=3D -=3D > a set([2]) ;; On bytes, bytearray and string objects all the following function works ;; see documentation py-format py-capitalize py-center py-endswith py-expandtabs py-find py-rfind py-isalnum py-isalpha py-isdigit py-islower py-isspace py-isupper py-istitle py-join py-ljust py-rjust py-rljust py-lower py-upper py-lstrip py-rstrip py-partition py-replace py-strip py-title py-rpartitio py-rindex py-split py-rsplit py-splitlines py-startswith py-swapcase py-translate py-zfill py-encode ;; translate a string object to a bytes object using UTF-8 per ;; default. py-decode ;; translates a bytes/bytearray object to a string object using ;; UTF-8 per default. ;; LISTS > (define l (py-list '(1 2 3 4))) > (pylist-ref l 0) 1 > (puylist-append! l 1) > l [1,2,3,4,1] > (pylist-slice 1 None None) ;; l[1:] [2,3,4,1] > (pylist-slice 1 2 None) ;; l[1:2] [2] > (pylist-slice None 2 None) ;; l[:2] [1,2] > (pylist-slice 1 None 2) ;; l[1:2:] [2,4] (pylist-subset l 1 3 None '(10 10)) ;; l[1:3] =3D '(10 10) > l [1,10,10,4,1] ;; pylist-ref and pylist-set! is single position setting and can be used fo= r ;; hash-maps strings lists vectors python lists bytevectors bytes bytearray= s ;; etc ;; We also have furthermore the following list and sequence types ;; pylist-insert! pylist-reverse! ;; pylist-append! pylist-listing pylist-set! ;; pylist-count pylist-null pylist-slice ;; pylist-delete! pylist-pop! pylist-sort! ;; pylist-extend! pylist-ref pylist-subset! ;; pylist-index pylist-remove! ;; FOR LOOPS ;; here is a generic map that works for all sequence types, > (define (map f l) (for ((x : l)) ((ret '())) (cons (f x) l) #:final l)) > (map (lambda (x) (+ "-" x)) "abc") ("-c "-b" "-a") > (map pk (bytes "abc")) ;; (97) ;; (98) ;; (99) > (define d (dict '((1 . 2) (3 . 4)))) > d 1: 2, 3: 4} > (for ((k v : d) (i : (range 10))) ((r -1)) (pk r k v i)) ;;; (-1 1 2 0) ;;; ( 0 3 4 1) ;; Further dictionary functions are: ;; py-copy py-fromkeys py-has_key py-items py-iteritems ;; py-iterkeys py-itervalues py-keys py-values ;; py-popitem py-setdefault py-update ;; py-hash-ref ;; LAMBDAS ;; One can get python lambda semantics if one wishes with =3D * ** ;; use (def (f (=3D x 1) (* l) (** kw)) ...) > (def (f a (* l) (=3D b 1) (** kw)) (list a l b kw)) > (f 1 2 3 #:q 1 #:w 2 #:b 3) (1 (2 3) 1 {"q": 1, "w": 2, "b": 3}) > (define f (lam (x y) (list x y))) > (f #:y 1 #:x 2) (2 1) ;; YIELD, python has a generator framework that i schemeified > (define-generator (gen1 yield l) (for-each yield l)) > (py-list (gen1 '(1 2 3))) [1, 2, 3] > (define gen2 (make-generator (lambda (yield l) (for ((x : l)) () (yield x))))) > (py-list (gen2 #(1 2 3))) [1, 2, 3] > (define-generator (gen3 yield l1 l2) (yield-from yield (gen1 l1)) (yield-from yield (gen2 l2))) > (py-list (gen3 '(1 2 3)) "abc") [1, 2, 3, "a", "b", "c"] ;; there is also utilities: ;; ;; next send sendException ;; ;; se Python doc's for for them On Thu, Sep 17, 2020 at 8:50 AM Zelphir Kaltstahl < zelphirkaltstahl@posteo.de> wrote: > Hi Stefan! > > Can you explain a little more how it is used? > > If I understand correctly, one could write Scheme code, but with forms, > which implement (by themselves or in some combination) Python keywords > or Python semantics. You mentioned, that it does not have a Python > compiler. So there is no way of translating Python into the Scheme code > for those modules. Basically that is a different concern, separation of > concerns, modularization, better maintainability, etc.? > > Do you have an example project, where this separated code is used in? > > Regards, > Zelphir > > On 12.09.20 19:59, Stefan Israelsson Tampe wrote: > > Hi, > > > > I am the author of python-on-guile and I just took out the scheme > > infrastructure for python and put it is a self contained project of not > too > > large size. It does not have a python compiler and cannot use python > code. > > So scheme only. > > > > You can find the project at > > > > docs for the interfaces is mostly documented at, > > http://c-lambda.se/python-on-guile/ > > -- > repositories: https://notabug.org/ZelphirKaltstahl > >