practicalli / practicalli/clojure

`type`, `class`, `instance?`

Open
#84 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

summary:
type is showing you a concrete type, rather than the abstractions that type implements

Looking at the documentation for type I see how to find a type of an object. And in the see-also section it talks about the function instance? which tests whether an object is a member of a designated class.
Is the documentation using the word class and type interchangeably here?
What is the correct way to check type membership, assuming I have a type designator compatible with isa? ?

According to the doc:

user=> (doc type)
-------------------------
clojure.core/type
([x])
  Returns the :type metadata of x, or its Class if none

From what I've seen, it looks like type/isa? and class/instance? are counterparts with each other.

class and instance? dealing strictly with java object hierarchy; type/isa? deal with derived types, falling back to Java classes if no derived type hierarchy is available.

No, as far as I understand isa? takes two type designators and tells whether one is a subtype of the other. I'm looking for a function which takes an object and a type designator and asks whether the object is a member of that type.

i.e., something that can be called like instance? but which accepts any 1st argument which is compatible with isa?

(isa? (type x) y)?

(isa? (type a-value) a-type) vs (instance? a-class an-object)

But because isa? and type fall back to Java type hierarchy, they will likely fit.

and since you mention you have an isa? compatible type designator, type would make more sense to me.

Thanks. But since I really don't understand all the flexibility of isa?, what's the best way to test my code? How can I generate a huge set of isa? compatible arguments and corresponding instances? Perhaps I could look at the testing code for isa? itself? Does anyone know how to locate that?

Are you using derived types? Or is that what you're looking at doing?

Hi penryu, for the moment here is what I think I'm doing. I'm implementing a DSL which lets the user talk about types. I want to claim on my DSL that I accept any type which isa? supports.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the documented (doc type) entry and compare it with the isa? and instance? references discussed in the issue. Determine whether the documentation needs to distinguish concrete classes, derived types, and type membership. Done means the terminology and the correct membership approach are clearly documented, with any relevant testing guidance identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.