Differences between prismatics schema and clojure.spec - clojure

I have just recently started to learn some clojure and in order to make something like types (more like contracts) for validations etc, the go-to solution is a library named schema.
Recently I learned that clojure 1.9 however will have something similar named clojure.spec
Can anyone please tell me the differences between them?
When should I use one or the other, pros and cons, etc?

Eric Normand did this comparison, but as already pointed out you should definitely check the rationale, and there is also the guide and a podcast where Rich Hickey talks abouts clojure.spec.

The spec rationale is quite in-depth, I would suggest reading it: https://clojure.org/about/spec after that feel free to compare it with any other library you may be considering.

Related

Writing a DSL in C++ with boost::proto

Apologies for asking such an open-ended question, but I want to emulate some synthetic assembly (not for a real processor) in C++ and I want to decouple the assembly from the implementation of the simulator it runs on.
Writing a DSL or similar seems like the obvious way and I have some experience of this, having done something like it (actually a mixture between a DSL and an interpreter) in Groovy.
boost::proto seems like the obvious choice, but I find the documentation utterly impenetrable, even though, as I say, I have some grasp of the basics.
Is there any alternative tutorial or similar out there that explains - in a way that focuses on the practicalities of writing a DSL rather than the theory of ASTs etc - how to do this. Or is there an alternative? Right now I am stuck with implementing the assembly instructions as methods of classes that make up the simulator, which makes them very tightly bound and extremely difficult to maintain the code base.
I second the comments suggesting that you may have a badly matched XY-problem here.
Meanwhile, the best introduction to applied Boost Proto for an embedded eDSL was on Dave Abrahams' cpp-next.com blog. Sadly, that has gone off the air.
Eric Niebler, author of Boost Proto, has offerred to send people the raw dumps of those pages, on request:
The C++ community is suffering from the loss of the cpp-next.com website and all the great content that was once hosted there. In the past 2 months, I’ve gotten many questions both about the site and about the fate of my “Expressive C++” article series. In response, I will re-post my old articles on this blog. But I’m busy and it’ll take time. In the meanwhile, if you have a desperate need for a readable introduction to Boost.Proto and domain-specific embedded languages in C++, and you don’t mind reading raw markdown, email me. I’ll send you what I have.
http://ericniebler.com/2014/05/24/cpp-next-com-and-the-expressive-cxx-series-2/
In the mean time, waybackmachine has some of it, e.g.:
http://web.archive.org/web/20120906070131/http://cpp-next.com/archive/2011/01/expressive-c-expression-optimization/
http://web.archive.org/web/20120315111227/http://cpp-next.com/archive/2010/10/expressive-c-expression-extension-part-one/
http://web.archive.org/web/20120430163700/http://cpp-next.com/archive/2010/10/expressive-c-expression-extension-part-two/
*

Concise Explanation of Core.logic

I want to use Clojure's Core.logic. However, I want to also understand how it works. Is there a concise explanation of it somewhere? (Like implementing a metacircular evaluator?)
Thanks!
core.logic is an implementation of miniKanren - originally written and designed in Scheme by Dan Friedman, William Byrd, Oleg Kiselyov and others. It is an attempt to embed Prolog-style relational programming within Lisp.
If you want to understand how it works you'll need to read the first three chapters of William Byrd's dissertation: https://scholarworks.iu.edu/dspace/bitstream/handle/2022/8777/Byrd_indiana_0093A_10344.pdf?sequence=1
The Reasoned Schemer also covers the unifier in detail. However the much more subtle goal portion of miniKanren isn't given a comprehensive treatment - you'll need to look at Byrd's dissertation for that.
Even then, as with meta-circular interpreters - many insights cannot be gained without trying to implement the system yourself in a variety of programming languages.
You can also see David's talk on core.logic from the Strange Loop 2012.
And for very light introduction to the topic see also: sokuza-kanren

Understanding Mini-Kanren's Execution Model

Chapter 5 of SICP explains the scheme meta circular evaluator interns of a register machine.
Is there anything that provides a similar type of Mini-Kanren in terms of Scheme primitives?
I know that there is a Thesis written on Mini-Kanren (however, I only care about building a mental model; not all the gory optimizations details). I also know that there is the reasoned-schemer -- however, I'm not looking for a bunch of examples -- I just want to understand Mini-kanren in its' very very basic form, much like how one can understand scheme by understanding: eval, apply, if, set!, env
Thanks!
I think reading The Reasoned Schemer is actually the right way to learn the basics. You could also try watching Dan Friedman and William Byrd's miniKanren talk from Clojure Conj.
Since miniKanren only has seven forms total, understanding the basic forms is really just understanding the whole thing. The implementation is only about a page of macros, so you could try to understand that. You could also try reading the introductory parts of William Byrd's PhD thesis.
In the book The Reasoned Schemer there's an implementation of a very simple logic system on top of Scheme. It's self-contained, the only thing needed for understanding it is the book itself, which - in the style of the other books in the series, is extremely easy to follow.

Learning Clojure by reading core.clj

I came across the tweet today:
Start each day by reading the implementation of a function or macro in Clojure's core.clj.
My Clojure knowledge is really basic, I can hardly read other's Clojure (or Lisp) code.
Can I do well with core.clj, especially I have the feeling it is full of complicated macros?
I think a better place to start is by doing a project; anything that interests you and seems manageable is good.
core.clj is not readable right now; perhaps the latter half is, but the first half isn't something I'd wish on anyone as an introduction to the language. The truth is, even if you read it very carefully, you'd not have a solid idea of what was going on without also reading a lot of Java code, too.
Make an asynchronous text-based game (technomancy—Phil Hagelburg—has a nice one to look through on his Github, though it's a little dated by now)
Scrape websites using the Enlive library.
Maybe just solve some math problems, and/or
Graph things using Incanter.
Build first. Once you acquaint yourself with the tools you are using, start reading them. The libraries mentioned here are well written (you can't go wrong with anything by Christophe Grand, for instance), and once you start using them, you'll understand what they do, which makes it much simpler to figure out the why and how later.
That tweet is probably a great idea once you have enough experience to be able to read Clojure code well enough to understand what is going on.
Before that point, I'd recommend gaining a strong familiarity with the language by writing a lot of small mini-programs. It's best to learn by doing, after all.
I personally found Project Euler very useful while I was learning Clojure.
You might also take a look at the Clojure Koans, though they may be a bit beginner-oriented for you, depending on how much Clojure you already know.
As a good starting point, I would recommend 4Clojure. It looks similar to Project Euler and Code Katas, but has more forgiving learning curve.
There's a lot I don't understand in it, but there's also a lot I do, and it's fascinating looking at the language getting bootstrapped from its minimal initial implementation.
Another place to look for little projects to get you going would be any of the Kata repos. My personal favorite at this point is Coding Kata.org, but there's also Coding Dojo, Ruby Koans (with a little translation effort), and of course Google.
Try to do one of those a day and you'll quickly pick up the language.
Try reading the Clojure contrib libraries or look at some Clojure projects on github to get a better feel for idiomatic Clojure code.
The advice above is good. Another fine example of learning-by-doing is well illustrated here by the creator of Ruby on Rails: How Do I Learn to Program? I hope you have an app that you care about that you could just go for in Clojure.
I find the clojure.core a good way to find ideas of how things are implemented, as more of a reference guide. As noted earlier, the early parts or neither pretty nor exemplary. However, the later parts can be a good example especially when needing to write a function that is close to core function but different.

Developing as a programmer

I have been learning C++ for three months now and in that time created a number of applications for my company. I consider myself fairly comfortable with C++ / MFC and STL, however I don't just want to be an OK programmer, I want to be a good programmer. I have a few books on best practices but I was wondering if anyone could suggest reading materials that helped them and any disciplines which should be encouraged?
Thanks!
I would start with the Pragmatic Programmer, Code Complete, Refactoring and Design Patterns.
For C++, Scott Meyers books are very good, and will help take you to the next level.
If you don't already have it C++ by Bjarne Stroustrup, 3rd Edition
Uhm... Teach Yourself Programming in Ten Years (Peter Norvig)
3 months into c++ and you're already comfortable with it? Sheesh, I've been learning c# for over a year and have taken numerous Microsoft courses and I'm nowhere near comfortable with it.
That being said, you'll hear Code Complete tossed about as a very good book. I'm in the process of reading it now.
Marshall Cline's C++ FAQ Lite.
Herb Sutter's Exceptional C++.
Large Scale C++ Software Design by John Lakos gives guidance on design methods that will make your C++ more maintainable. It is pretty hefty but you can dip in and still get some benefits.
Somewhat off-topic: rather than suggesting books to learn, I'd like to mention some broad topics to consider.
Threading. This one is not much in demand if you use MFC, but in many other areas it's indispensable. The mechanics of threading APIs are easy to pick up, but learning all the corner cases takes a lot of time and practice.
Closures, Map-Reduce and other lisp-like techniques. Find out what they are, why they are not supported in C++, and how they are imitated in C++ (functors, and many other cases of stateful callback objects). For this I actually have a book: "Structure and Interpretation of Computer Programs".
Command Line. This gives you an idea on when not to code your own programs. Command line would be Unix command line - I don't know about MS's latest experimentation in this are, but cmd.exe is awful. Get Cygwin and start experimenting.
Scripting languages. This gives you an idea on when not program in C++. My favorite is Perl, but many people say Python, Ruby and whatnot. Hey, learn XSLT if you're so inclined!
I am sure I left out other areas. I'll mark this as Community Wiki - feel free to add.
Good blogs:
Guru of the Week, and all the books by Herb Sutter. Those will give you quite a lot to chew already.
Modern C++ Design by Alexandrescu if you want to get a good feel for what you don't yet know, and probably don't want to know.
Code Kata's for practice!
I have read several (not complete but some parts) of oreilly books on VB.net they are quite good, but if you want to be pro and have the time...
You can try out MSDN forums, help other people and discuss with them hard and complex problems, I think it's the best way..
learn another language. even if you won't use it, it's great for mind-opening.
I'd advice Lua, Scheme and Python. but almost anything else would do. (the most different from C, the best)
Josuttis and Vandevoorde - Templates: The Complete Guide
As I see, nobody mentioned Bruce Eckel brilliant books "Thinking in C++". IMHO, it`s one of the best books to start your C++ development from. From my point of view, first volume is more helpful that the second, but both of them worth reading.
http://www.amazon.com/Thinking-C-Introduction-Standard-One/dp/0139798099/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1227890306&sr=8-1
I lot of folks can suggest more modern, up-to-date books. But I still recommend The Annotated C++ Reference Manual by Margaret A. Ellis & Bjarne Stroustrup.
The ARM was published back in '90. It's become somewhat outdated with respect to templates. STL is (obviously) absent. (Though the website at sgi.com does a good job of covering STL!)
However, the ARM is dirt cheap (used). (Shipping will exceed the cost of the book.) Its signal-to-noise ratio remains off the scale. It's very good at digging into C++'s dirty areas, explaining what was done & why.
I still use it as a reference. I rank it up there with K&R.
Dietel/Dietel "How to program C++"... I still have this book on my desk (10 years in).. Every once and a while I re-read a chapter. I'd definatly get the Code Complete, as other have suggested. Infact read that first.
To get a better understanding of object orientation, spend some time in a Smalltalk. Squeak is a free download. Then read Richard P. Gabriel's Patterns of Software and thereafter his Objects have Failed.
Thinking in C++ - Bruce Eckel
Symfonia C++ Standard - Jerzy Grębosz
If you do nothing else, program.
When you are not doing that read about programming and when something strikes you as interesting, go implement something with that knowledge. I've found that this is the only way to really set the principals.
Staying up to date on blogs can be fun, but it is scattered knowledge. It seems to distract more than help. But combined with google and a desire to research something specific can really cough up tons of information. But dont' just subscribe to alot of rss feeds and expect to get better.
I think really studying specific topics helps expand your ability. Research topics that intrigue you, meet people doing things like you (conferences, user groups, irc, facebook, stackoverflow, etc) and above all practice your art.
You can check out the Boost library and a number of the books written about it. While this may not have been what you had in mind, IMO, the Boost libraries are examples of well-designed modern C++ libraries that use the features of the language in pretty much the way they should be used to create among the most effective solutions for their problem domain. Granted of course, there are bizarre libraries like preprocessor and MPL which make you wonder if you'll ever have any use for them, but they're all round quite good. From my own experience, exploring the library and its literature has given me insight into how C++ can be used effectively.
Boost
Beyond the C++ Standard Library: An Introduction to Boost