quoting vs syntax quoting

2020-03-02 Thread Sonny To
(defmacro moo1 []
  '(defn foo []))

(defmacro moo2 []  

 
  `(defn foo []))

stigmergy.wocket.server> (moo1)
 
#'stigmergy.wocket.server/foo

   
stigmergy.wocket.server> (moo2)
 
CompilerException clojure.lang.ExceptionInfo: Call to clojure.core/defn did 
not conform to spec:
In: [0] val: stigmergy.wocket.server/foo fails spec: 
:clojure.core.specs.alpha/defn-args at: [:args :name] predicat\
e: simple-symbol?  
 
 #:clojure.spec.alpha{:problems [{:path [:args :name], :pred 
clojure.core/simple-symbol?, :val stigmergy.wocket.ser\
ver/foo, :via [:clojure.core.specs.alpha/defn-args 
:clojure.core.specs.alpha/defn-args], :in [0]}], :spec #object[c\
lojure.spec.alpha$regex_spec_impl$reify__2436 0x33d84248 
"clojure.spec.alpha$regex_spec_impl$reify__2436@33d84248"]\
, :value (stigmergy.wocket.server/foo []), :args 
(stigmergy.wocket.server/foo [])}, compiling:(*cider-repl workspac\
e/clj-collage:localhost:39319(clj)*:131:26)

stigmergy.wocket.server> (macroexpand-1 '(moo1))  
(defn foo [])   

stigmergy.wocket.server> (macroexpand-1 '(moo2))  
(clojure.core/defn stigmergy.wocket.server/foo [])   




moo1 uses normal quoting while moo2 uses syntax quoting. Why does (moo1) 
succeeds but( moo2) fails? Both seem to evaluate to same data-structure 
except moo2 has namespaces.

The error message is cryptic but it seems moo2 is failing on 
clojure.core/simple-symbol? 
which seems like a symbol without a namespace.  How can I make a symbol 
without a namespace in syntax quoting?




-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/8d7b6fc7-5dcc-45fd-a19b-b424b295a27f%40googlegroups.com.


Re: JNA stdout and the REPL

2020-02-14 Thread Sonny To
here is an example of 



 

> package foo; 
>   
> 
>
> import com.sun.jna.Library;
> 
> 
> import com.sun.jna.Native;
> 
>  
> import com.sun.jna.Pointer;
> 
> 
>   
> 
>  
> public interface C extends Library {  
> 
>  
> C INSTANCE = (C) Native.load("c",C.class);
> 
>  
>   
> 
>  
> void printf(String format, Object... args);
> 
> 
> }  
> 
> 

 

calling this from a java main like this works as expected at the command 
line
  C.INSTANCE.printf("hello\n");

but from the clojure REPL,

(.printf foo.C/INSTANCE "hello "(into-array []))  


does not show anything

On Friday, February 14, 2020 at 6:30:51 PM UTC+8, Sonny To wrote:
>
> I am using JNA to call native C code. calling native code that outputs to 
> stdout does not show up in the Clojure REPL. stdout is redirected somewhere 
> that is not attached to *out*
>
> How can I get stdout from native code outputting to *out* in the REPL? 
> Without this, it makes it difficult to see what went wrong in the C code.
>
> thanks,
> Sonny
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/bd950525-defd-4696-948e-ac321dc5220e%40googlegroups.com.


JNA stdout and the REPL

2020-02-14 Thread Sonny To
I am using JNA to call native C code. calling native code that outputs to 
stdout does not show up in the Clojure REPL. stdout is redirected somewhere 
that is not attached to *out*

How can I get stdout from native code outputting to *out* in the REPL? 
Without this, it makes it difficult to see what went wrong in the C code.

thanks,
Sonny

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/c0e5756a-4f29-4ca2-876e-c2bb8c8d88b0%40googlegroups.com.


pair programming with tmux spacemacs on Mac/Linux

2019-10-07 Thread Sonny To
This is not clojure specific but has anyone successfully used spacemacs to 
pair programming with tmux and spacemacs? My pairing partner uses a mac 
with french Canadian keyboard but when he ssh into my box
to pair, his key bindings don't work even though I used his init.el The 
meta key and paredit keybidings don't work for him.

The keybinding works for me but I'm on Linux with a standard US keyboard. 
Appreciate any help!

Below is ~/.emacs.d/init.el and ~/.tmux.conf

---init.el---
(setq gc-cons-threshold 1)
(global-set-key (kbd "") 'meta)

;;(set-keyboard-coding-system nil)
(set-terminal-coding-system 'utf-8)
(setq mac-command-modifier 'meta)
;;(setq mac-command-key-is-meta t)
(setq mac-option-modifier  'none)

(add-to-list 'auto-mode-alist '("\\.cljs\\.hl\\'" . clojurescript-mode))
(add-hook 'clojure-mode-hook
  '(lambda ()
 ;; Hoplon functions and macros
 (dolist (pair '((page . 'defun)
 (loop-tpl . 'defun)
 (if-tpl . '1)
 (for-tpl . '1)
 (case-tpl . '1)
 (cond-tpl . 'defun)))
   (put-clojure-indent (car pair)
   (car (last pair))

(defconst spacemacs-version "0.200.13" "Spacemacs version.")
(defconst spacemacs-emacs-min-version   "24.4" "Minimal version of Emacs.")

(if (not (version<= spacemacs-emacs-min-version emacs-version))
(error (concat "Your version of Emacs (%s) is too old. "
   "Spacemacs requires Emacs version %s or above.")
   emacs-version spacemacs-emacs-min-version)
  (load-file (concat (file-name-directory load-file-name)
 "core/core-load-paths.el"))
  (require 'core-spacemacs)
  (spacemacs/init)
  (configuration-layer/sync)
  (spacemacs-buffer/display-startup-note)
  (spacemacs/setup-startup-hook)
  ;; BEGIN exec-path-from-shell
  (use-package exec-path-from-shell
  :ensure t
  :if (memq window-system '(mac ns x))
  :config
  (setq exec-path-from-shell-variables '("PATH" "SOLR_HOME"))
  (exec-path-from-shell-initialize))
  ;; END exec-path-from-shell
  (require 'server)
  (unless (server-running-p) (server-start)))
-end init.el

--.tmux.conf---
set -g prefix C-z
unbind-key C-b
bind-key C-z send-prefix
set-option -g default-terminal "xterm-256color"
set-window-option -g xterm-keys on

--end .tmux.conf---





-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/d5ff4535-35c9-4a67-8549-6149985f6a11%40googlegroups.com.


[ANN] Voodoo a Clojure library for byte buffer manipulation

2019-09-03 Thread Sonny To
https://github.com/sonwh98/voodoo 


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/11d1f934-c8ed-4ccb-8cf4-f9281f4e3be4%40googlegroups.com.


Re: dynamically defining specs

2019-02-19 Thread Sonny To
s/def is a macro so it doesn't evaluate the parameter n.
had to use s/def-impl instead like this


  (let [n :foo/bar3
f int?]
(s/def-impl n n f)
)

On Tuesday, February 19, 2019 at 1:18:20 PM UTC+1, Sonny To wrote:
>
> (let [n :foo/bar
> f int?]
> (s/def n f)
> )
>
> (s/get-spec :foo/bar)
>
> why does this return nil?
>
> it seems I can only define a spec like this
>
> (s/def :foo/bar int?)
>
> Is there a way to programmatically create a spec from data?
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


dynamically defining specs

2019-02-19 Thread Sonny To
(let [n :foo/bar
f int?]
(s/def n f)
)

(s/get-spec :foo/bar)

why does this return nil?

it seems I can only define a spec like this

(s/def :foo/bar int?)

Is there a way to programmatically create a spec from data?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] Ikota

2018-12-13 Thread Sonny To
It has reagent like components. I extracted this library out while creating a 
reagent like library without a dependency on react.js

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] Ikota

2018-12-13 Thread Sonny To
Yet another Hiccup implementation for Clojure and ClojureScript

https://bitbucket.org/sonwh98/ikota/src/master/



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] CHP Clojure Hiccup Page

2018-12-13 Thread Sonny To
https://bitbucket.org/sonwh98/chp/src/master/

PHP is popular for server-side web development because it is easy to get 
started. It was initially designed to be a templating language to create 
dynamic HTML pages on the server-side. PHP pages are HTML pages with 
embedded code.


CHP borrows this idea from PHP but improves on it. Instead of HTML and PHP 
code, Hiccup  and Clojure 
are used.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What is the minimal Emacs config for practical Clojure development?

2018-07-09 Thread Sonny To
Not sure what you mean by minimum but here's instruction on setting up a 
dev environment that works for me
http://lambdakids.stigmergy.systems/2018/6/6/hello-world.blog

my emacs init.el is at https://bit.ly/2z3gtyi 

On Monday, July 2, 2018 at 6:41:23 AM UTC+3, Austin Haas wrote:
>
> I don't want to use a package manager with Emacs.
>
> Should I launch a REPL outside of Emacs, then connect to it? Using the CLI 
> tools (i.e., from the command line: clojure -J-Dclojure.server.repl="{:port 
>  :accept clojure.core.server/repl}")?
>
> Can I launch a REPL from within Emacs?
>
> I've been using inf-clojure and clojure-mode with the following elisp in 
> my .emacs:
>
> (add-to-list 'load-path "~/.emacs.d/site-lisp/third-party/clojure-mode/")
> (require 'clojure-mode)
> (add-to-list 'load-path "~/.emacs.d/site-lisp/third-party/inf-clojure/")
> (load-file "~/.emacs.d/site-lisp/third-party/inf-clojure/inf-clojure.el")
> (add-hook 'clojure-mode-hook #'inf-clojure-minor-mode)
> (setf inf-clojure-lein-cmd "lein run -m clojure.main")
>
> and C-c C-z to start a REPL, but I get noise in the REPL, including 
> repeated prompts, and (seemingly) random linebreaks in large output.
>
> What's the state of the art for a simple, practical Emacs setup for 
> Clojure?
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: accessing symbols in local context of a closure

2018-05-26 Thread Sonny To
James,
that works but i would use a record instead of something like that. I want 
to extract the local bindings only with a var to the closure. I thought 
there might be some meta data or properties i can access.

Josh, I didn't think about using java reflection api. thanks!

On Saturday, May 26, 2018 at 9:23:05 AM UTC+3, James Gatannah wrote:
>
>
>
> On Friday, May 25, 2018 at 7:40:12 AM UTC-5, Sonny To wrote:
>>
>> Hi James,
>> I'm trying to access the local bindings of the closure like it is an 
>> object
>> (.-x bar) should give  1. I can use a defrecord for this but I want to 
>> use regular functions and no macro magic
>>
>
> This isn't quite what you're asking for, but one approach to what records 
> actually do would be to return a map of closures that include accessors for 
> the state. (Disclaimer: I'm totally doing this off the top of my head in 
> the google groups web interface, without even checking that the parentheses 
> are balanced) One example would be:
>
> (defn build-incrementer
>
>   [x]
>
>  {:inc (fn [] (inc x))
>   :dec (fn [] (dec x))
>   :status (fn [] x)})
>
> Is that close to what you wanted?
>
> Regards,
> James
>  
>
>>
>> On Friday, May 25, 2018 at 9:01:22 AM UTC+3, James Gatannah wrote:
>>
>>> On Thursday, May 24, 2018 at 1:22:42 PM UTC-5, Sonny To wrote:
>>>>
>>>> (defn foo[]
>>>>  (let [x  1]
>>>>(fn []  
>>>>  (+ x 1)
>>>> )
>>>>  )
>>>>
>>>> (def bar  (foo))
>>>>
>>>> Is there a way to get the value of x from closure bar?
>>>>
>>>
>>> I may be describing this incorrectly.
>>>
>>> You're creating a top-level var named bar.
>>>
>>> You're calling the function foo, and associating the value it returns to 
>>> that var bar.
>>>
>>> foo's return value happens to be a function that looks like it should be 
>>> a counter. Except that, in clojure, it isn't.
>>>
>>> This vaguely looks like an approach to lexical closures that I vaguely 
>>> remember from scheme textbooks (and Paul Graham essays).
>>>
>>> What are you really trying to do?
>>>
>>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: accessing symbols in local context of a closure

2018-05-25 Thread Sonny To
Hi James,
I'm trying to access the local bindings of the closure like it is an object
(.-x bar) should give  1. I can use a defrecord for this but I want to use 
regular functions and no macro magic

On Friday, May 25, 2018 at 9:01:22 AM UTC+3, James Gatannah wrote:

> On Thursday, May 24, 2018 at 1:22:42 PM UTC-5, Sonny To wrote:
>>
>> (defn foo[]
>>  (let [x  1]
>>(fn []  
>>  (+ x 1)
>> )
>>  )
>>
>> (def bar  (foo))
>>
>> Is there a way to get the value of x from closure bar?
>>
>
> I may be describing this incorrectly.
>
> You're creating a top-level var named bar.
>
> You're calling the function foo, and associating the value it returns to 
> that var bar.
>
> foo's return value happens to be a function that looks like it should be a 
> counter. Except that, in clojure, it isn't.
>
> This vaguely looks like an approach to lexical closures that I vaguely 
> remember from scheme textbooks (and Paul Graham essays).
>
> What are you really trying to do?
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


accessing symbols in local context of a closure

2018-05-24 Thread Sonny To
(defn foo[]
 (let [x  1]
   (fn []  
 (+ x 1)
)
 )

(def bar  (foo))

Is there a way to get the value of x from closure bar?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


macro to unwrap a list

2016-02-15 Thread Sonny To
I am trying to write a macro to unwrap a list:

here's my naive attempt

(defmacro unwrap [s]
  (-> s pr-str  (clojure.string/replace #"[\(\)]" "") read-string))

(unwrap (1 2 3) ) should give 1 2 3

any ideas how this can be done?

thanks,
Sonny

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.