Comments (3)
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.
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.
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)
- TRANSLATE-EXPRESSION on NODE-FOR is buggy HOT 4
- into-iter bug
- for sometimes causes a runtime type error
- add tests for all core language looping constructs
- Inliner doesn't work with `return` HOT 1
- `:coalton/benchmark` deprecated/impendingly deprecated HOT 1
- Improve presentation of low-level reader errors HOT 1
- Type error on over-application of anonymous functions
- Coalton package form: support "shadow" clause
- reference page links are broken HOT 2
- add warning when exported symbol denoting a value doesn't have an explicit type declaration
- Bad error message for undefined type in `Declare`
- Fun (Bad) error message for duplicate definitions in the same toplevel
- Misleading error for toplevel operations in the repl
- Error messages are way too long and don't get wrapped around in Emacs
- Duplicate key errors don't indicate source location HOT 1
- `Unused variable` error encourages additionally declaring the function name to be unused.
- SB-EXT package lock violation when trying to load Coalton via Quicklisp HOT 2
- Unclear error message for heterogenous list
- type-error during printing of typechecker error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coalton.