Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remove :as support from use expressions

The `:as` keyword in use statements really just confuses the meaning of
`use` and `require` make some interactions surprising. By removing this
`use` always behaves exactly as expected.
  • Loading branch information...
commit 636d8108ecafa632266bc3c9951525cedf12c631 1 parent 1e81e9f
Eric Merritt authored
6 doc/language.rst
Source Rendered
@@ -335,8 +335,7 @@ we might want to do.
335 335
336 336 (use (string :exclude (substr/4 join/2)
337 337 :joxify
338   - :rename ((sub-word/3 str-subword) (join/2 str-join)
339   - :as str)))
  338 + :rename ((sub-word/3 str-subword) (join/2 str-join))))
340 339
341 340 Lets break this down into actions.
342 341
@@ -360,9 +359,6 @@ Lets break this down into actions.
360 359 imports being carried forward. *NOTE* note the joxification of
361 360 `sub-word/3`. Since we specified `joxify` earlier we must must
362 361 refer to it as `sub-word/3` instead of `sub_word/3`.
363   -5) As. This has the exact as in `require` in that it provides an alias
364   - for the namespace name specified. This allows you to refer to any
365   - function in that namespace with the alias.
366 362
367 363 Functions
368 364 ---------
3  examples/complex_module.jxa
@@ -3,8 +3,7 @@
3 3 (attr sfoo 123)
4 4 (use (lists :only (member/2 append/2)
5 5 :rename ((member/2 mbr))))
6   - (use (file :as f
7   - :exclude (delete/1)
  6 + (use (file :exclude (delete/1)
8 7 :rename ((change_group/2 chgrp)
9 8 (change_mode/2 chmod))))
10 9 (attr super_duper "Hello World")
3  examples/sieve-of-eratosthenes.jxa
... ... @@ -1,6 +1,6 @@
1 1 (ns sieve-of-eratosthenes
2 2 (require lists io)
3   - (use (joxa.core :as core :only (!=/2))
  3 + (use (joxa.core :only (!=/2))
4 4 (erlang :only (rem/2 +/2))))
5 5
6 6 (defn sieve (v primes)
@@ -13,4 +13,3 @@
13 13
14 14 (defn+ sieve (v)
15 15 (sieve (lists/seq 2 v) 1))
16   -
28,669 src/ast/joxa-compiler.ast
14,330 additions, 14,339 deletions not shown
9 src/joxa-compiler.jxa
@@ -2008,9 +2008,6 @@
2008 2008 ({{fun arity} alias}
2009 2009 {{fun arity} (joxify-name alias)})))
2010 2010 imports0)))
2011   - (('(quote as) . (alias-name . rest))
2012   - (add-alias-ctx ctx alias-name namespace-name)
2013   - (handle-use-clauses path ctx rest namespace-name imports0))
2014 2011 (('(quote only) . (target-funs . rest))
2015 2012 (when (and (erlang/is_atom namespace-name)
2016 2013 (is-list target-funs)))
@@ -2026,8 +2023,8 @@
2026 2023 (is-list target-funs)))
2027 2024 (let* (imports1 (rename-funs path ctx target-funs imports0))
2028 2025 (handle-use-clauses path ctx rest namespace-name imports1)))
2029   - (probably-more-uses
2030   - (make-use path ctx probably-more-uses namespace-name imports0))))
  2026 + (_
  2027 + (add-error-ctx ctx path {:invalid-use-clause {:bad-use-part forms}}))))
2031 2028
2032 2029 (defn namespace-exists? (mod-name)
2033 2030 (case (code/ensure_loaded mod-name)
@@ -4241,6 +4238,8 @@
4241 4238 "invalid namespace declaration")
4242 4239 (:invalid-sequence
4243 4240 "invalid sequence")
  4241 + ({:invalid-use-clause {:bad-use-part forms}}
  4242 + (io_lib/format "invalid use clause ~p" [forms]))
4244 4243 ({:invalid-reference {f -1}}
4245 4244 (io_lib/format "invalid reference ~s" [(format-fun-ref f) ]))
4246 4245 ({:invalid-reference {f a}}
29 src/joxa-shell.jxa
@@ -14,16 +14,25 @@
14 14 lists
15 15 ec_dictionary
16 16 joxa-compiler)
17   - (use (erlang :only (atom_to_list/1 list_to_binary/1 apply/3))
18   - (joxa-core :as core)))
  17 + (use (erlang :joxify
  18 + :only (==/2
  19 + or/2
  20 + get-stacktrace/0
  21 + atom-to-list/1
  22 + list-to-binary/1
  23 + make-fun/3
  24 + is-list/1
  25 + apply/3))
  26 + (joxa-core :only (if/3
  27 + try/1))))
19 28
20 29 (defn prompt (ctx)
21   - (lists/concat [(atom_to_list (joxa-compiler/namespace-name-ctx ctx))
  30 + (lists/concat [(atom-to-list (joxa-compiler/namespace-name-ctx ctx))
22 31 "> "]))
23 32 (defn read (ctx)
24 33 (case (io/get_line (prompt ctx))
25   - (r (when (erlang/is_list r))
26   - (erlang/list_to_binary r))
  34 + (r (when (is-list r))
  35 + (list-to-binary r))
27 36 (else
28 37 else)))
29 38
@@ -31,12 +40,12 @@
31 40 (let* (result (joxa-compiler/comp-interactive ctx :--joxa-shell parse [])
32 41 comp-res
33 42 (if (joxa-compiler/compilable? ctx)
34   - (if (erlang/== result :expr)
35   - (let* (call-fun (erlang/make_fun (joxa-compiler/namespace-name-ctx ctx) :--joxa-shell 0))
  43 + (if (== result :expr)
  44 + (let* (call-fun (make-fun (joxa-compiler/namespace-name-ctx ctx) :--joxa-shell 0))
36 45 (call-fun))
37 46 :ok)
38   - (if (erlang/or (erlang/== result :expr)
39   - (erlang/== result :defn))
  47 + (if (or (== result :expr)
  48 + (== result :defn))
40 49 :error
41 50 result)))
42 51 (joxa-compiler/clear-errors ctx)
@@ -63,7 +72,7 @@
63 72 (catch
64 73 (e
65 74 (io/format "error: ~p : " [e])
66   - (io/format "~p~n" [(erlang/get_stacktrace)])
  75 + (io/format "~p~n" [(get-stacktrace)])
67 76 (loop ctx <<>>)))))
68 77
69 78 (defn+ start ()
2  test/jxat_examples.erl
@@ -18,7 +18,7 @@ prop_seive() ->
18 18 Source = <<"
19 19 (ns jxat-sieve-of-eratosthenes
20 20 (require lists io)
21   - (use (joxa-core :as core :only (!=/2))
  21 + (use (joxa-core :only (!=/2))
22 22 (erlang :only (rem/2 +/2))))
23 23
24 24 (defn sieve (v primes)
3  test/jxat_featureful_module.erl
@@ -9,7 +9,7 @@ given([a,featureful,module], _State, _) ->
9 9 (attr sfoo 123)
10 10 (use (lists :only (member/2 all/2)
11 11 :rename ((member/2 mbr))))
12   - (use (file :as f
  12 + (use (file
13 13 :exclude (delete/1)
14 14 :rename ((change_group/2 chgrp)
15 15 (change_mode/2 chmod))))
@@ -40,7 +40,6 @@ then([the,joxa,context,for,a,featureful,module,is,correctly,formed], Ctx0, _) ->
40 40 ?assertMatch(true, ec_dictionary:has_key({erlang, integer_to_list, 2}, Required)),
41 41 ?assertMatch(true, ec_dictionary:has_key({code, which, 1}, Required)),
42 42 ?assertMatch(proplists, ec_dictionary:get(props, Alias)),
43   - ?assertMatch(file, ec_dictionary:get(f, Alias)),
44 43 ?assertMatch("Hello World",
45 44 proplists:get_value(super_duper,
46 45 'jxat-featureful':module_info(attributes))),

0 comments on commit 636d810

Please sign in to comment.
Something went wrong with that request. Please try again.