Public Vars

Back

seq? (clj)

(source)

variable

(seq? x)
Return true if x implements ISeq

Examples

clojure/core.typed
(ns clojure.core.typed.test.destructure
  (:import (clojure.lang APersistentVector APersistentMap))
  (:require [clojure.core.typed :as t :refer [ann-form check-ns cf]]))

(let* [map__65083 {} 
       map__65083 (if (seq? map__65083) 
                    (clojure.lang.PersistentHashMap/create (clojure.core/seq map__65083)) 
                    map__65083) 
       b (get map__65083 :b 3)] 
  (ann-form b Number))
clojure/core.typed
(ns clojure.core.typed.test.cljs-core
    (:require [cljs.core.typed :as t]
              [cljs.core :as core]
              [clojure.core.typed.test.cljs-utils :refer [is-tc-e tc-e]]
              [clojure.test :refer :all]))

(add-test1 seq?
    (seq [1 2 3]) t/JSBoolean
    [1 2 3]       t/JSBoolean)

(add-test1 seq?
    []           t/JSBoolean
    #{2 3}       t/JSBoolean
    (seq [1 2])  t/JSBoolean
    (seq #{2 3}) t/JSBoolean)
hraberg/deuce
(ns deuce.emacs.eval
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c]
            [deuce.emacs.alloc :as alloc]
            [deuce.emacs.data :as data]
            [deuce.emacs-lisp.cons :as cons]
            [deuce.emacs-lisp :as el])
  (:import [clojure.lang Var])
  (:refer-clojure :exclude [apply eval macroexpand]))

(defun functionp (object)
  "Non-nil if OBJECT is a function."
  (when (or (fn? object)
            (and (symbol? object) (el/fun object))
            (and (seq? object) (= 'lambda (first object))))
    true))

  The second optional arg ENVIRONMENT specifies an environment of macro
  definitions to shadow the loaded ones for use in file byte-compilation."
  ;; Not sure how this is supposed to work even after reading eval.c, attempts to mimic observed behavior.
  ;; It is used in conjunction with cl-macroexpand-all, and should not expand into "raw" Clojure.
  (let [shadow (into {} (map #(vector (data/car %) (data/cdr %)) environment))
        shadow #(shadow % (shadow (str %)))
        unshadowed-form ((fn shadow-walker [form]
                           (if-let [expander (shadow form)]
                             (if (= '(true) (data/cdr-safe expander))
                               (cons (first (data/car expander))
                                     (map #(list 'quote %) (rest (data/car expander))))
                               (expander form))
                             (if (and (seq? form)
                                      (not= 'quote (first form)))
                               (cons/maybe-seq (map shadow-walker form))
                               form))) form)
        expansion (if-let [m  (and (seq? form) (-> (el/fun (first form)) meta))]
                    (if (and (:macro m) (= (the-ns 'deuce.emacs-lisp) (:ns m)))
                      unshadowed-form
                      (macroexpand-1 unshadowed-form))
                    unshadowed-form)]
    ;; Protect against eq check in cl-macroexpand-all
    (if (= form expansion)
      form
      expansion)))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/seq? (t/Pred (t/Seq t/Any))
cc/set? (t/Pred (t/Set t/Any))
cc/vector? (t/Pred (t/Vec t/Any))
cc/nil? (t/Pred nil)
#?@(:cljs [
cc/undefined? (t/Pred t/JSundefined)
])
cc/false? (t/Pred false)
cc/true? (t/Pred true)
cc/symbol? (t/Pred t/Sym)
cc/keyword? (t/Pred t/Keyword)
cc/map? (t/Pred (t/Map t/Any t/Any))
cc/boolean? (t/Pred t/Bool)
cc/any? [t/Any :-> true]
cc/record? (t/Pred #?(:clj clojure.lang.IRecord
                      :cljs cljs.core/IRecord))


;; START CHUNK HACKS
;; These are hacks to get around the expansion of doseq>
;; Basically, inference isn't good enough to narrow a (t/Seqable x) to 
;; an (IChunk x), because chunked-seq? needs to be (t/Pred (IChunk t/Any)).
#?@(:cljs [] :default [
cc/chunked-seq? [t/Any :-> t/Any]
cc/chunk-first 
     (t/All [x]
          ;should be IChunkedSeq :-> IChunk
          [(t/Seqable x) :-> (clojure.lang.IChunk x)])
cc/chunk-rest
     (t/All [x]
          ;should be IChunkRest :-> t/Seq
          [(t/Seqable x) :-> (t/ASeq x)])
cc/chunk-buffer
     (t/All [x]
          [(t/U Integer Long) :-> (clojure.lang.ChunkBuffer x)])
cc/chunk
     (t/All [x]
          [(clojure.lang.ChunkBuffer x) :-> (clojure.lang.IChunk x)])
cc/chunk-cons
     (t/All [x]
          [(clojure.lang.IChunk x) (t/Seqable x) :-> (t/ASeq x)])
cc/chunk-append
     (t/All [x]
          [(clojure.lang.ChunkBuffer x) x :-> t/Any])
;;END CHUNK HACKS
])
typedclojure/typedclojure
(ns ^:no-doc typed-test.clj.ext.clojure.core__let
  (:require [clojure.test :refer [deftest is testing]]
            [clojure.core.typed :as t]
            [typed.clj.checker.parse-unparse :as prs]
            [typed.clj.checker.test-utils :refer :all]))

(deftest common-destructuring-test
  ;; Note: different combinations of & and fixed vector args
  ;; generate very different code
  (is-tc-e (let [[a] [1]]
             (ann-form a Number)))
  (is-tc-e (let [[a b] [1 2]]
             (ann-form a Number)
             (ann-form b Number)))
  (is-tc-e (let [[& a] [1]]
             (ann-form a (t/Seq Number))))
  (is-tc-e (let [[a & b] [1 2]]
             (ann-form a Number)
             (ann-form b (t/Seq Number))))
  (is-tc-e (let [[a b & c] [1 2 3]]
             (ann-form a Number)
             (ann-form b Number)
             (ann-form c (t/Seq Number))))
  (is-tc-e (let [[a b c d e & r :as all] [1 2 3 4 5 6 7]]
             (ann-form b Number)
             (ann-form c Number)
             (ann-form d Number)
             (ann-form e Number)
             (ann-form r (t/Seqable Number))
             (ann-form all (t/Seqable Number))))
  (is-tc-e (seq [1 2 3])
           (t/HSeq [t/Num t/Num t/Num]))
  (is-tc-e
    '(1 2 3)
    (t/HSeq [t/Num t/Num t/Num]))
  (is-tc-e
    '(1 2 3)
    (t/HList [t/Num t/Num t/Num]))
  (is-tc-e
    (seq '(1 2 3))
    (t/HSeq [t/Num t/Num t/Num]))
  (is-tc-e
    (let [[a b c & d :as e] '(1 2 3 4 5 6 7)]
      (ann-form a (t/Val 1))
      (tc-ignore (assert (= 1 a) (pr-str a)))
      (ann-form b (t/Val 2))
      (tc-ignore (assert (= 2 b) (pr-str b)))
      (ann-form c (t/Val 3))
      (tc-ignore (assert (= 3 c) (pr-str c)))
      (ann-form d (t/HSeq [(t/Val 4) (t/Val 5) (t/Val 6) (t/Val 7)]))
      (tc-ignore (assert (seq? d) (pr-str d))
                 (assert (= [4 5 6 7] d) (pr-str d)))
      (ann-form e (t/HSeq [(t/Val 1) (t/Val 2) (t/Val 3)
                           (t/Val 4) (t/Val 5) (t/Val 6) (t/Val 7)]))
      (tc-ignore (assert (seq? e) (pr-str e))
                 (assert (= [1 2 3 4 5 6 7] e) (pr-str e)))))