Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Last active December 31, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustingetz/823f1f9a08cd9de53415edea97b9e38a to your computer and use it in GitHub Desktop.
Save dustingetz/823f1f9a08cd9de53415edea97b9e38a to your computer and use it in GitHub Desktop.

Unbalanced if with effect

(defn- pprint-list [alis]
  (if-not (pprint-reader-macro alis)
    (pprint-simple-list alis)))

When without effect

(defn- diff-associative-key
  "Diff associative things a and b, comparing only the key k."
  [a b k]
  (let [va (get a k)
        vb (get b k)
        [a* b* ab] (diff va vb)
        in-a (contains? a k)
        in-b (contains? b k)
        same (and in-a in-b
                  (or (not (nil? ab))
                      (and (nil? va) (nil? vb))))]
    [(when (and in-a (or (not (nil? a*)) (not same))) {k a*})
     (when (and in-b (or (not (nil? b*)) (not same))) {k b*})
     (when same {k ab})
     ]))

When with effect

(if (> (count pclasses) 18)
  (else-gen gen m)
  (do
    (when is-overload
      (emit-get-var gen (overload-name mname pclasses))
      (. gen (dup))
      (. gen (ifNonNull found-label))
      (. gen (pop)))
    (emit-get-var gen mname)
    (. gen (dup))
    (. gen (ifNull else-label))
    (when is-overload
      (. gen (mark found-label)))
    ;if found
    (.checkCast gen ifn-type)
    (when-not as-static
      (. gen (loadThis)))
    ;box args
    (dotimes [i (count ptypes)]
      (. gen (loadArg i))
      (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
    ;call fn
    (. gen (invokeInterface ifn-type (new Method "invoke" obj-type
                                          (to-types (replicate (+ (count ptypes)
                                                                  (if as-static 0 1))
                                                               Object)))))
    ;(into-array (cons obj-type
    ;                 (replicate (count ptypes) obj-type))))))
    ;unbox return
    (. gen (unbox rtype))
    (when (= (. rtype (getSort)) (. Type VOID))
      (. gen (pop)))
    (. gen (goTo end-label))

    ;else call supplied alternative generator
    (. gen (mark else-label))
    (. gen (pop))

    (else-gen gen m)

    (. gen (mark end-label))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment