Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save svanellewee/1609f1d3691b43c2e7e3e4e96acb0fd6 to your computer and use it in GitHub Desktop.
Save svanellewee/1609f1d3691b43c2e7e3e4e96acb0fd6 to your computer and use it in GitHub Desktop.
C mode go mode code comparison
(require 'ert)
(require 'org-id)

;; (setq load-file-name "~/.emacs.d/github/ob-go/")

(require 'ob-go)
;; ob-go

;;>> (a "abc" "def")


(org-babel-go-var-to-go '(x . 12))
(org-babel-go-var-to-go '(a "abc" "def"))
(defun org-babel-go-var-to-go-2 (pair)
  "Convert an elisp var into a string of go source code
specifying a var of the same value."  
  (let ((var (car pair))
        (val (cdr pair)))
    (message ">> %S" pair)
    (when (symbolp val)
      (setq val (symbol-name val)))
    ;; TODO(pope): Handle tables and lists.
    (format "var %S = %S" var val)))


(setq examples '(( (x . 2) .  "var x = 2")
                 ( (a "abc" "def") . "var a = []string{\"abc\", \"def\"}")
		   ( (tabletest (1) (2) (3)))))
(mapcar #'org-babel-go-var-to-go-2 (mapcar #'car examples))

1
2
3
100
return tabletest2
(require 'ob-C)
;;(org-babel-C-var-to-C '())
;;(let ((cases '(12 x "hello" 0.2 (x 12) (x . 12) (x . "hello"))))
(mapcar #'list
        (list 
         (org-babel-C-val-to-C-type 12)
         (org-babel-C-val-to-C-type 'x)
         (org-babel-C-val-to-C-type "gello")
         (org-babel-C-val-to-C-type 0.2)
         (org-babel-C-var-to-C '(x 12))
         (org-babel-C-var-to-C '(x . 12))
         (org-babel-C-var-to-C '(x . "hello"))
         (org-babel-C-var-to-C '(x . "hello"))
         ))
(let ((cases '(12 x "hello" 0.2)))
  (mapcar #'org-babel-C-val-to-C-type cases))
(let ((cases '((x 12) (x . 12) (x . "hello") (x . "hello"))))
  (mapcar #'org-babel-C-var-to-C cases))
(let ((cases '((x 12 "hello" (2 3)))))
  (mapcar #'org-babel-C-var-to-C cases))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment