Clojure-Intro-Course / clojure-intro-class

NOTE: This repository is obsolete. Was: A pilot project to use Clojure for introductory computer science courses at the University of Minnesota - Morris
20 stars 3 forks source link

Use clojure.spec instead of atom and function overwriting #108

Open elenam opened 8 years ago

elenam commented 8 years ago
real-mj-song commented 8 years ago

screenshot from 2016-06-23 16-12-06

real-mj-song commented 8 years ago

clojure.lang.ExceptionInfo: Call to #'spec-ex.spec-inte/+ did not conform to spec: :: {:clojure.spec/problems {[:args] {:pred number?, :val "", :via [], :in [4]}}, :clojure.spec/args (3 4 6 7 "")} In: [4] val: "" fails at: [:args] predicate: number? :clojure.spec/args (3 4 6 7 "")

Note: the message is "Call to #'spec-ex.spec-inte/+ did not conform to spec:", the rest is data.

elenam commented 8 years ago

Specs for core functions need to be defined before the function is redefined or in a different file.

real-mj-song commented 8 years ago
elenam commented 8 years ago

For nilable predicates the data is:

{:clojure.spec/problems {[:args :check-map :clojure.spec/nil] {:pred nil?, :val :s, :via [], :in [0]}, 
[:args :check-map :clojure.spec/pred] {:pred map?, :val :s, :via [], :in [0]}}, :clojure.spec/args (:s)}
real-mj-song commented 8 years ago

For some functions, we need to put specs after overwriting them (and we can't get the function name in this case). I think this happens in two cases.

  1. When the function has different numbers of :inline-arities like #{2 3}
  2. When the function has only :inline without :inline-arities