Releases: ETHproductions/japt
The 2.0a0 Update
Mostly releasing this to match v1.4.5, so as not to break older answers. In addition to everything listed in the Overdue Update, includes several new features:
- The code has been cleaned up enormously, and method definitions are no longer golfed (why did I even do that?).
- Regex literals have been added, which auto-balance parentheses and brackets.
- Backslashes now make single-class regex literals.
- Division must now be done with
÷
.
Also, 500 commits! Whoo!
The Overdue Update
I should release more often... I mean, 13 months? Really?
General added features
- Added
%c
and%C
character classes (consonants +y
and anything else, respectively) (#50). - Added
%p
and%P
character classes (printables and anything else, respectively). - Added
%q
and%Q
character classes (printables + newline and anything else, respectively). - Added 7 shortcuts:
Ê
(l
),Ë
(mDEF{D
),Ì
(gJ
),Í
(n2
),Î
(g
),Ï
(XYZ{Y
),Ñ
(*2
). - Added
Math.approx
function, which rounds out errors of a magnitude less than 10n (default n = 5). - Each line except the last is now assigned to a variable, in order
U
,V
,W
,X
,Y
,Z
,A
,B
,C
, ...T
(not that anyone will ever get anywhere near that far)
Bug fixes/improvements
S.e()
used theg
flag by default, breaking the effect of logging each successive replacement (#31).A.o(n)
assumedn
was an integer, entering infinite loops if it wasn't (#37).A.r(f)
now starts with the first element if no starting value is given.A.x()
returnedNaN
if any of its elements couldn't be parsed as a number.A.z(n)
broke somehow. I think the fix broke it in a different way.- Auto-functions in
A.ä(f)
andA.å(f)
didn't use both inputs. A.ç(a)
both modifiedA
and filled the array with references rather than copies ofa
.A.í(f,a)
didn't swap arguments.N.k()
,N.ç()
, andN.î()
usedthis
as a Number object rather than a pure number (#35).N.v()
now acts as if all numbers are divisible by0
.- Switched from
String.fromCharCode
toString.fromCodePoint
(#42). - Added more implicit commas before decimal points.
- General fixes with implicit
U
s. - General fixes with
$interpolated JS$
. - Balance parentheses inside
?:
, adding an extra layer if necessary. - Make
++
and--
take precedence over anything else, adding a layer of parentheses. - Remove many unnecessary layers of parentheses to improve readability.
- Add spacing to improve readability. (Only permanent side-effect is breaking The Polyglot)
- More I haven't yet mentioned and don't remember.
New String methods
S.k(s)
; removes chars ins
(opposite ofS.o(s)
).S.k(f)
; removes chars that satisfyf
(opposite ofS.o(f)
).S.n(s)
; converts from bases.length
to integer usings
as the alphabet.S.n(a)
; same as above, but with an array of items making up the alphabet.S.o(f)
; keeps only the chars that satisfyf
(similar toA.f(f)
).S.y(f)
; maps each column throughf
.S.í(s,f?)
; pairs each char with the corresponding one ins
, optionally mapping each pair throughf
.S.ù/ú/û(n,s=" ")
; left/right/center-pads each line to lengthn
withs
.S.ù/ú/û(s=" ")
; left/right/center-pads each line to form a rectangle.
New Array methods
A.e(a)
; returns whether the two arrays are equal (#42)A.k(f)
; removes items that satisfyf
(opposite ofA.f(f)
).A.y(f)
; maps each column throughf
.A.ì(s)
; converts from bases.length
to integer usings
as the alphabet.A.ì(a)
; same as above, but with an array of items making up the alphabet.A,ï(a,f?)
; Cartesian product, mapping each pair throughf
. If noa
is given, usesA
again.A.ù/ú/û(n,s=" ")
; left/right/center-pads each line to lengthn
withs
.A.ù/ú/û(s=" ")
; left/right/center-pads each line to form a rectangle.
New Number methods
N.a(n)
; absolute difference betweenN
andn
.N.d(n)
; gets character at codepointN+n
.N.j(n)
; whetherN
is coprime ton
(they share no prime factors).N.s(f)
; converts to string, maps throughf
, then converts back to number.N.s(s)
; converts from integer to bases.length
usings
as the alphabet.N.s(a)
; same as above, but with an array of items making up the alphabet.N.y(n=2)
; GCD. (Even works on decimals, thanks toMath.approx
!)N.z(n=2)
; integer division.N.ì(s)
; converts from integer to bases.length
usings
as the alphabet.N.ì(a)
; same as above, but with an array of items making up the alphabet.
I should keep better track of my changes to make it easier to write these changelogs. Or maybe I could just release an update every few weeks or months so I don't forget what I've done...
The Monster Update
Whew! I've done a lot since v1.4.3 was released at the end of January. It's now the end of May, so let's see what all has been accomplished in 4 months:
General added features
- Added 5 shortcuts:
Å
(s1
),Æ
(o@
),Ç
(o_
),È
(XYZ{X
),É
(-1
) - Added the
%L
character class (matches anything butA-Za-z
). - Added experimental permutation and combination functions using caches (not enabled though); the new permutation function seems to be way faster than the old on large arrays, but the new combination function is slower.
- Added shims for
String.prototype.contains
,Array.prototype.contains
, andMath.trunc
so I can safely use them throughout the code. - Added flags (see below for a list).
- Any of
a-zà-ÿ*/%^|&<=>?
after a semicolon is now prepended with aU
. (This already happened at the beginning of a program or function)
Bug fixes/improvements
regexify(x)
fails ifx
is not a string or a regex.- Arrays don't show up in the output of the
str()
function (hencestr(1)
andstr([[[1]]])
both return"1"
). - Literal strings are returned verbatim from the
str()
function (as opposed to String objects, which are wrapped in quotes). A.r()
fails if given an auto-function without a second parameter.S.m()
does not properly accept three arguments (e.g."abc de f"mp2S -> "abcabc dede ff"
).- Fixed numerous bugs where large numbers would be destroyed due to use of
|0
for truncation. - Fixed code for
M.q()
andM.r()
so that they actually do what they're supposed to. - Centralized all code for
N.ò()
,N.ó()
, andN.ô()
inN.o()
to fix some inconsistencies. \x
(wherex
is any char) transpiles to a number if within a function.#
at the end of the program throws a transpile-time error.- There are often unnecessary double parentheses in the output.
- Nested compressed strings don't end implicitly.
5.5.5
,A.5
,1e2e3
, etc. are transpiled verbatim.
New String methods
S.a(f)
andS.b(f)
; these return the first/last index wheref
returns a truthy value.S.c(f)
; this works likeS.m(f)
, but on char-codes.S.ç(s=" ")
: replaces each char inthis
withs
.S.ê(n=0)
: ifn%2 < 1
, mirrorsthis
around its last character; otherwise, appends its reverse.S.ê(s)
: returnstrue
ifthis
is a palindrome (i.e. equal to its reverse);false
otherwise.S.î(s=" ")
: repeatss
until it reachesthis.length
.S.ò(n=2)
; cutsthis
into slices of lengthn
."abcde"ò2 -> ["ab","cd","e"]
S.ò(f)
; partitionsthis
between charsX, Y
wheref(X,Y)
is truthy."abba"ò@X<Y} -> ["a","bba"]
.S.ó(n=2)
; cutsthis
inton
arrays of everyn
th char."abcde"ó2 -> ["ace","bd"]
S.ó(f)
; partitionsthis
between charsX, Y
wheref(X,Y)
is falsy."abbc"ó@X<Y} -> ["ab","bc"]
.S.ô(f)
; partitionsthis
at charsX
wheref(X)
is truthy."abca"ô@X>'b} -> ["ab","a"]
S.ö()
; returns a random character ofthis
.S.ö(n)
; returns a string ofceil(n)
random characters ofthis
(with replacement).S.ö(x)
; returns a random permutation ofthis
.S.ø(s)
; returnstrue
ifthis
containss
,false
otherwise.S.ø(a)
; returnstrue
ifthis
contains any element ofa
,false
otherwise.
New Array methods
A.a(f)
andA.b(f)
; these return the first/last index wheref
returns a truthy value.A.f(a,n=0)
:- if
n%3 === 0
, selects the items inthis
that are also contained ina
; - if
n%3 === 2
, selects each item contained in boththis
anda
; - if
n%3 === 1
, selects each item that can be removed from boththis
anda
.
- if
A.k(a)
; removes all items ina
fromthis
.A.x(f)
; performsA.m(f)
then takes the sum.A.ê(n=0)
: ifn%2 < 1
, mirrorsthis
around its last item; otherwise, appends its reverse.A.ê(s)
: returnstrue
ifthis
is a palindrome (i.e. equal to its reverse);false
otherwise.A.í(n=10)
: convertsthis
from an array of base-n
digits to a decimal number.A.î(a=[0])
: repeatsa
until it reachesthis.length
.A.ò(n=2)
; cutsthis
into slices of lengthn
.[1,2,3,4,5]ò2 -> [[1,2],[3,4],[5]]
A.ò(f)
; partitionsthis
between itemsX, Y
wheref(X,Y)
is truthy.[1,2,0,3]ò@X>Y} -> [[1,2],[0,3]]
A.ó(n=2)
; cutsthis
inton
arrays of everyn
th char.[1,2,3,4,5]ò2 -> [[1,3,5],[2,4]]
A.ó(f)
; partitionsthis
between itemsX, Y
wheref(X,Y)
is falsy.[1,2,0,3]ò@X<Y} -> [[1,2],[0,3]]
A.ô()
; partitionsthis
at itemsX
whereX
is falsy.[1,2,0,3]ô -> [[1,2],[3]]
A.ô(f)
; partitionsthis
at itemsX
wheref(X)
is truthy.[1,2,3,1]ô@X>2} -> [[1,2],[1]]
A.ö()
; returns a random element ofthis
.A.ö(n)
; returns an array ofceil(n)
random elements ofthis
(with replacement).A.ö(x)
; returns a random permutation ofthis
.A.ø(x)
; returnstrue
ifthis
containsx
;false
otherwise.A.ø(a)
; returnstrue
ifthis
contains any element ofa
;false
otherwise.
New Number methods
N.â(x?)
: returns all integer divisors ofthis
. Ifx
is truthy, doesn't includethis
.N.ç(s=" ")
; repeatss
this
times.N.î(s=" ")
; repeatss
until it reaches lengththis
.N.õ(n=1,n=1)
; likeo
, but creates the range[n₁...this]
(with step size ofn₂
), and the range is not reversed ifthis
is less thann₁
.N.õ(f)
; maps each integer in[1...this]
throughf
.N.ö()
; returns a random item ofthis.o()
.N.ö(n)
; returns an array ofceil(n)
random items ofthis.o()
(with replacement).N.ö(x)
; returns a random permutation ofthis.o()
.
New Math features
M.e
:Math.exp
M.l
:Math.log
M.m
:Math.log2
M.n
:Math.log10
M.T
: tau (pi * 2)
New flags
-m
: Map; runs the program on each item in the input, returning an array of the results. If the input is a number, it's turned into a range first; if the input is a string, it's split into chars beforehand and joined again afterwards.-f
: Filter; runs the program on each item in the input, returning an array of only the items that return a truthy value. If the input is a number, it's turned into a range first; if the input is a string, it's split into chars beforehand and joined again afterwards.-æ
: A shortcut for-fg
; runs the program on each item, returning the first one that returns a truthy value.-d
: Some; runs the program on each item, returning true if any returns a truthy value, false otherwise.-e
: Every; runs the program on each item, returning false if any returns a falsy value, true otherwise.-g
: Returns the first item in the output. If given a number (-g3
), returns the nth item.-h
: Returns the last item in the output.-!
: Returns the boolean NOT of the output: true if the output is falsy; false otherwise.-¡
: Converts to boolean: returns true if the output is truthy; false otherwise.-N
: Converts the output to a number.-P
: If the output is an array, outputs with no separator (i.e. joined withP
).-Q
: Pretty-prints the output, wrapping strings in quotes and arrays in brackets.-R
: If the output is an array, outputs separated by newlines (i.e. joined withR
).-S
: If the output is an array, outputs separated by spaces (i.e. joined withS
).-x
: Calls.x()
on the output. If the output is an array, sums; if the output is a string, trims whitespace from both ends.
The next big step is to clean up the code...
More features, more fixes
One of the defining features of Japt is its lack of arity, so I've been trying to give more functions dual purposes depending on how many arguments they are given. You can see that here with A.c(), N.n(), and D.n().
- Added feature:
K
now returnsnew Date()
by default - Added feature: implicit U if first char is any of
*/%^|&<=>?
- Added shortcuts:
Ä
(+1
) and×
(r*1
) - Added function: A.ñ(f) sorts
A
as if each value has been run throughf
- Added function: N.h(n=1) performs
N.toPrecision(n)
- Added function: N.x(n=0) performs
N.toFixed(n)
- Added function: D.n() casts
D
to a number, D.n(n) does the same as N.n(n) - Added function: F.c(f) is like F.a(f), but with all integers: 0, -1, 1, -2, 2, -3, 3...
- Modified function: A.c(x) concatenates
x
toA
- Modified function: N.n(n=0) returns
n-N
- Bug fix: A.n() always sorts lexicographically by default
- Bug fix: auto-functions don't work with A.æ()
- Bug fix: auto-functions don't work with N.o()
- Bug fix: textboxes are emptied if URL contains no
code=
orinput=
Added and improved a bunch of functions
- Bug fix:
à-ÿ
are not accepted in shorthand functions - Bug fix: A.d(), A.e(), A.f(), and A.è() do not properly accept shorthand functions, e.g.
f>2
- Greatly improved the speed of A.æ() by returning as soon as the first item is found
- Made N.j() (primality check) twice as fast
- Combined N.h() with N.u() (positive modulus)
- Made N.v() into a divisibility check
- Added S.ë(n,x=0): returns every
n
th char ofthis
, starting at indexx
- Added A.ë(n,x=0): returns every
n
th item ofthis
, starting at indexx
- Added A.ì(x): converts
this
from an array of base-x
digits to an integer - Added N.ì(x): converts
this
into an array of base-x
digits - Added F.a(f?): returns the smallest non-negative integer that returns a truthy value when run through
this
, mapping throughf
beforehand - Added F.b(f?): like F.a(), but with bijective base-10 integers
Minor improvements and fixes
- Added feature: implicit
U
added if the first char in the code is a lowercase letter - Bug fix:
MP
becomesM,P
instead ofM.P
- Minor documentation improvements
Japt 1.4: too many improvements to list
This one's a biggy, stretching for more than a year and 205 commits. The main difference is that the internals have been completely rearranged, so the functions that were run
and transpile
before are now Japt.run
and Japt.transpile
. You can find all the differences here.
Japt 1.3: string compression, Unicode shortcuts, and many new functions
Over the last few days, vihanb and I have implemented a bunch of new features, bug fixes and enhancements:
- String functions:
d
- Recursive replacee
- Single-char replace and multiple-replaceo
- Select chars
- Array functions:
u
- Unshiftv
- Shift
- Number functions:
a
- absolute valuej
- primality testk
- prime factorizationl
- factorial
- Math functions:
t
- atan2g
- fibonaccir
- randomP
- PI
- String compression (using the shoco library):
Oc
- compress ASCII textOd
- decompress pre-compressed text- text wrapped in backticks - auto-decompress
- Unicode shortcuts:
¡
-Um@
¢
-Us2
£
-m@
¤
-s2
¥
-==
¦
-!=
§
-<=
¨
->=
©
-&&
ª
-||
«
-&&!