naru is a programming language designed for world domination. To the best extent of our knowledge, this didn’t happen yet. Until then this website is under construction.
This website is available in multiple locations: narunaru.org, narucode.org and a part of noe.mearie.org. 이 문서의 한국어판은 여기서 볼 수 있습니다.
Seriously, naru is a programming language being designed by Kang Seonghoon since 2005, and still in development. (“naru” is pronounced NAH-roo, and always written in lower case.) It has several major goals:
Expressiveness and conciseness often harm each other; more features you put in, less concise the resulting code is. naru provides the reasonable trade-off between them. (And the solution is not a lisp way—sorry, but s-expression is a bit too much.)
Many users follow the default choice laid by the language designer (both unknowingly or intentionally), so the default choice is very important. For example, you may assume that one char
maps to one real character in languages that do not support Unicode, but that’s not correct. (And this is similar even in languages with Unicode string.) naru makes the right way to do things much easier, so users actually do the right thing by following the simplest path.
While static languages and dynamic languages are not complementary to each other, it is quite hard to see languages at the middle between them. That is because they do not offer advantages of two kinds of languages: performance, reliability and correctness (well, with a good typechecker) for static languages, expressiveness, rapid and easy development for dynamic languages. naru tries to provide both advantages.
Well, the syntax, for example, somewhat resembles Python and Ruby because the author is familiar to them. But many other aspects are originated from other languages (e.g. whitespace as a method/property access is inspired from ooc), or entirely new (e.g. with
). Since the author prefers cleaner and intuitive (read: so obvious that mistake is impossible) design, it is well reflected in the language design.
So far, naru has underwent several revisions in order to meet these various goals (the current one is named revision 4). No implementation is available currently, but once the rough design is finished, the reference implementation will surface.
This snippet implements a basic version of PHP’s getimagesize
function:
use naru
ImageType := type (:png | :gif | :jpeg)
(-- Returns a tuple of image type, width and height for given image stream, or
none if any error is occurred. Supports PNG, GIF (both 87a and 89a) and
JPEG (JFIF only) for now. --)
imagesize(f: Reader) -> (ImageType,Int,Int)? := fun
imgtype: Option{ImageType} = none
f position = 0
header = f read(24)
if header length != 24 then return none end -- too short!
if header[..!8] == b"\x89PNG\x0d\x0a\x1a\x0a" then
width, height = header[16..!24] asInt32(:big)
imgtype = :png
elseif header[..!6] in {b"GIF87a", b"GIF89a"} then
width, height = header[6..!10] asUInt16(:little)
imgtype = :gif
elseif header[..!4] == b"\xff\xd8\xff\xe0" and header[6..!10] == b"JFIF" then
blockgen() := fun
f position = 2
while f eof
f skipwhile(0xff)
blocktype, blocksize = f read(3) unpack([UInt8, UInt16], :big)
savedpos = f position
yield blocktype, blocksize
f position = savedpos + blocksize - 2 -- 2 for blocksize
end
end
-- filter out the SOFn block
sofns = blockgen() map(fun (t, _) -> 0xc0 <= t <= 0xcf)
for _ <- sofns
-- ignore precision byte
_, height, width = f read(5) unpack([Int8, UInt16, UInt16], :big)
imgtype = :jpeg
break
end
end
if t <- imgtype then
return (t, width, height)
else
return none
end
end
(-- Shortcut for imagesize(Reader). --)
imagesize(filename: String) := \
fun -> imagesize(File(filename) open())
(-- Returns a suitable XHTML text for given image file. It may return the invalid XHTML
(i.e. no width/height attributes) when the automatic size detection is failed. --)
htmlize(filename: String, alt: String = "") := fun
escape(s) := fun s -> s replace("&", "&") replace("<", "<") replace(">", ">")
do
_, width, height = imagesize(filename)
return #"""<img src="#(escape(filename))" width="#width" height="#height"
alt="#(escape(alt))" />"""
but
-- no dimension information available
return #"""<img src="#(escape(filename))" alt="#(escape(alt))" />"""
end
end
Note that nothing in this code is finalized yet.
Follow the links below:
Articles and reports for naru revision 4:
Obsolete articles and reports for naru:
The official IRC channel for naru is #naru at Ozinger IRC network.