Skip to content

Instantly share code, notes, and snippets.

Avatar

Christophe Grand cgrand

View GitHub Profile
@cgrand
cgrand / main.clj
Last active December 9, 2022 21:47
View main.clj
(ns workshop.main
(:require ["package:flutter/material.dart" :as m]
["package:google_fonts/google_fonts.dart" :as fonts]
#_["example.dart" :as ex]
[cljd.flutter.alpha2 :as f]))
(def normal-text-style
(fonts/GoogleFonts.sourceCodePro
.fontSize 26
.fontWeight m/FontWeight.w700
@cgrand
cgrand / t10s-expressive-datalog.cljc
Last active December 10, 2021 16:17
Putting expressions in datomic-flavored datalog :where clauses. (This is a snippet I had laying around and that I'd like to develop further.)
View t10s-expressive-datalog.cljc
(ns tensegritics.expressive.datalog
"Putting expressions in datomic-flavored datalog :where clauses.")
;; I (cgrand) believes that datalog literally lacks expressivity because
;; it's not expression-based but clause-based and thus requires a lot of
;; gratuitous naming.
;; Here is an attempt to compiles expressions into clauses.
(defn- grounded? [[e a v]] (and (keyword? a) (not (symbol? v))))
@cgrand
cgrand / doto.clj
Last active November 3, 2021 22:31
A usage of `doto` that I overlooked for years
View doto.clj
;; let's say you want to perform an action only when a state is true and returns true/false depending on the action success
;; typically I would write
(if @open ; check state
(do
(.put q bytes) ; action
true)
false)
;; or
@cgrand
cgrand / for.clj
Created July 14, 2021 14:58
ClojureDart's for macro
View for.clj
;; For ClojureDart in a bout of NIH syndrome we rewrote Clojure for
;; it seems to be faster because we don't use concat
(defmacro for
"List comprehension. Takes a vector of one or more
binding-form/collection-expr pairs, each followed by zero or more
modifiers, and yields a lazy sequence of evaluations of expr.
Collections are iterated in a nested fashion, rightmost fastest,
and nested coll-exprs can refer to bindings created in prior
binding-forms. Supported modifiers are: :let [binding-form expr ...],
:while test, :when test.
@cgrand
cgrand / main.dart
Created July 3, 2021 13:19
lazy init
View main.dart
log(String msg, x) {
print(msg);
return x;
}
var a = log("Init A", 1);
var b = log("Init B", 2);
var c = log("Init C", 3);
main() {
@cgrand
cgrand / super.md
Last active June 24, 2021 15:35
super in ClojureDart
View super.md

Accessing super members in ClojureDart

In ClojureDart deftype (and reify) can extend abstract classes and, as a consequence, we need a way to call super implementations (even on fields because of getters/setters).

For example, this Dart

class WebViewExampleState extends State<WebViewExample> {
  @override
 void initState() {
View fallback.md

Quick notes on how the fallback pseudo-type is used in cljd (ClojureDart).

Like cljs, cljd is built on protocols. Like in clj, each protocol is backed by an interface for the fast path. Let's call this interface the direct interface.

Cljd protocols are also backed by a second interface used for extensions to 3rd-party classes. Let's call this interface the extension interface.

Protocols are reified as instances of an IProtocol interface:

// emitted code
@cgrand
cgrand / gist:564d6e8ad57299f64beb438e4a8b709f
Created July 11, 2020 20:26 — forked from KingCode/gist:773560f4ab5bf91e660a2a26e581b036
cond-let and cond-let| macros, to leverage bindings between test and result expressions, as well as earlier ones (for cond-let)
View gist:564d6e8ad57299f64beb438e4a8b709f
;; (cond-let
;; (odd? x) [x n] (inc x)
;; (< n 10) [y (inc n)] 10
;; :else n))
;; we want the above to yield
;; (let [x n]
;; (if (odd? x)
;; (inc x)
@cgrand
cgrand / demo.clj
Last active July 4, 2019 10:00
EZ todo
View demo.clj
(ns enlivez.demo
(:require [enlivez.core :as ez]
[datascript.core :as d]))
(ez/deftemplate new-item []
:state {:db/id self
new-todo ""}
[:li
[:input {:value new-todo
:on-change (doto [[:db/add self ::new-todo (-> % .-target .-value)]] prn)}]
View Main.java
package doubetrouble;
import java.util.concurrent.Callable;
public class Main implements Callable<Object> {
private static class Constants {
final static Object constant;
static {