Skip to content

Commit

Permalink
Tweak wording
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Jan 29, 2021
1 parent 66fa9fc commit bef68e5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ by the Clojure compiler:
(infer "foo") ;=> java.lang.String
```

It can take one arbitrary expression and returns its static type as long as
the Clojure compiler can infer it:
It can take an arbitrary expression and returns its static type as long as
the Clojure compiler can infer:

```clojure
(infer (not false)) ;=> java.lang.Boolean
Expand All @@ -45,16 +45,16 @@ Otherwise (i.e. the compiler failed to infer the static type of the given expres
(infer cons) ;=> nil
```

The `infer` macro aims to be used mainly as a development tool for performance tuning,
especially when eliminating reflection warnings or taking full advantage of primitive types.
The `infer` macro is mainly intended to be used for performance tuning, and is especially
useful for removing reflection warnings and taking full advantage of primitive types.

In most cases, `infer` per se is hard to use in your function or macro.
In most cases, `infer` per se is difficult to use in your function or macro.
If you want to use it in your macro, it's highly recommend to use `infer-type` below instead.

### `infer-type`

The `infer-type` fn takes two arguments. The first one is the macro's implicit argument
`&env` and the second one is a symbol. To get `&env`, you need to call it in a macro:
The `infer-type` fn takes two arguments: The first one is the implicit macro argument
`&env` and the second one is a symbol. To get `&env`, you need to call `infer-type` in a macro:

```clojure
(require '[type-infer.core :as ty])
Expand All @@ -70,8 +70,8 @@ The `infer-type` fn takes two arguments. The first one is the macro's implicit a
```

Note that `infer-type` only accepts a symbol as its second argument.
If you want to pass arbitrary expression to it, you'll need to pass it via a `let` form
like the following:
If you want to pass arbitrary expression to it, you'll need to pass the expression
via an extra `let` form like the following:

```clojure
(defmacro my-infer-type [x]
Expand All @@ -83,12 +83,12 @@ like the following:

Note also that due to the above limitation, the target expression of the type inference
may be evaluated at most once. This means that it is impossible (or difficult at best)
to implement macros using `infer-type` such that the original expression is never evaluated
in the expanded form, e.g. constant folding.
to implement macros using `infer-type` such that the input expression is never evaluated
in the expanded form.

## Practical use

Examples of practical use of the library can be found in the following products:
Examples of practical use of the library can be found in the following projects:

- [sweet-array](https://github.com/athos/sweet-array)
- [power-dot](https://github.com/athos/power-dot)
Expand Down

0 comments on commit bef68e5

Please sign in to comment.