Giter Site home page Giter Site logo

Comments (3)

Izaakwltn avatar Izaakwltn commented on September 27, 2024 2

In terms of wrappers, this might be a preferable approach:

(coalton-toplevel

  (define (createtable)
    (Lisp Unit ()
      (post:query (:create-table 'persons ((name :type cl:string) (age :type cl:integer))))))
  
  (define (insert)
    (Lisp Unit ()
      (post:query (:insert-into 'persons :set :name "Alain" :age 20))
      (post:query (:insert-into 'persons :set :name "Alain" :age 30)))))

This way you would have native Coalton functions that perform the sql operations, without any of the lisp predefinitions.

I don't have a database connected right now, so I'm not sure about the return types of these functions, but this frame should work.

from coalton.

devosalain avatar devosalain commented on September 27, 2024 1

Code below works !!!,


(load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3) (space 0) (debug 3)))
(ql:quickload "serapeum")
(ql:quickload "fiasco")
(ql:quickload "coalton")
(ql:quickload "postmodern")

(defpackage mymain
  (:use #:cl
        #:serapeum)
  (:export main)) ;defpackage

(defpackage mycoalton
  (:use #:coalton 
        #:coalton-prelude)
  (:local-nicknames (#:co #:cl) (#:pm #:postmodern))
  (:export cmain) ) ;defpackage

(in-package :mycoalton)
(coalton-toplevel
    (declare myconnect ( Unit -> Unit ))
    (define (myconnect)
        (Lisp Unit()
            (pm:connect-toplevel "x" "x" "x" "127.0.0.1" :port 5432 ) 
            Unit))
    (declare myquery ( Unit -> String ))
    (define (myquery)
        (Lisp String()
            (co:let ((myname nil)
                       (myage  nil)
                       (mysum  nil))
                (pm:doquery (:select 'name 'age :from 'persons)
                    (myname myage)
                    (co:setf mysum (co:concatenate co::'string mysum (co:format nil "~a:~a ~%" myname myage))))
                mysum)))
    (declare cmain ( Unit -> Unit ))
    (define (cmain)
        (myconnect)
        (Lisp Unit()
            (co:format co:t "~a ~%" (myquery Unit))
            Unit) 
        Unit)) ;toplevel

(in-package :mymain)
(-> main () Integer )
(defun main ()
	(mycoalton:cmain coalton:Unit)
	0 ) ; main
(sb-ext:save-lisp-and-die "test.exe" :toplevel #'main :executable t)

from coalton.

Izaakwltn avatar Izaakwltn commented on September 27, 2024

If you want to handle this with package management, which may be useful for larger situations:

It might work to have two packages, A lisp package with postmodern free to do what it wants, and then a coalton package importing the cl-package.

(defpackage #:mytest-backend
   (:use #:cl #:postmodern)
   (:export <functions>)

(in-package #:mytest-backend)

<cl function definitions>

(defpackage #:mytest
    (:use #:coalton
             #:coalton-prelude
             #:mytest-backend)

(in-package #:mytest)

<Coalton code>

This will let you avoid all the cl: prefixes and also have a defined space in your project for the postmodern backend
.
It also might be more practical to just add a local-nickname for postmodern, which would avoid the name clash:

(defpackage #:mytest
    (use #:coalton
            #:coalton-prelude)
    (local-nicknames (#:post #:postmodern)))

You'll have to use the prefix post: on postmodern functions but it would be easier than redefining myeverythings.

If you do find that it makes sense to keep the lisp definitions at the top, I'd recommend making two packages, so you can avoid all the

from coalton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.