lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 10 April 2013 18:49, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2013/4/9 Dirk Laurie <dirk.laurie@gmail.com>:
>
>> Lua's existing syntax *is* lambda syntax, but for the sake of
>> portability the three symbols required are spelt out with keywords.
>
> Portability-shmortability. Get yourself a font that displays all
> of Unicode properly and configure your keyboard to make the
> Unicode characters you need with the alternate graphic key.
>    http://en.wikipedia.org/wiki/AltGr_key
>
> The attached patch to Lua 5.2 allows the syntax
>
>     ∆(a,b) → a+b ⋄
>
> Actually, all Lua keywords have been replaced by single Unicode
> symbols, as a service to those who find Lua code obfuscated when
> using English words like 'function' and 'return' instead of symbols.
>
> Here is a sample:
>
>  ⊣ i ∊ pairs(_G) ⊢ print(i) ⋄  -- prints the global table
>  ⍳ 2<3 ⊥ print(∪) ⊤ print(∩) ⋄ -- prints "true"
>
> The mapping of Unicode symbols to Lua terminals is defined
> in the patch to llex.c.

Just for fun, here's a larger snippet of translated Lua code (I just
ran 'sed' on some code, and picked slightly different symbols). It
doesn't look _that_ bad, to be honest!

----------
λ build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
   assert(type(rockspec_file) == "string")
   assert(type(need_to_fetch) == "boolean")

   ▷ rockspec, err, errcode = fetch.load_rockspec(rockspec_file)
   ⟦ err ⟧
      → nil, err, errcode
   Ⅱ ¬ rockspec.build ⟧
      → nil, "Rockspec error: build table not specified"
   Ⅱ ¬ rockspec.build.type ⟧
      → nil, "Rockspec error: build type not specified"
   •

   ⟦ deps_mode == "none" ⟧
      util.printerr("Warning: skipping dependency checks.")
   Ⅱ
      ▷ ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode)
      ⟦ err ⟧
         → nil, err, errcode
      •
   •

   ok, err, errcode = deps.check_external_deps(rockspec, "build")
   ⟦ err ⟧
      → nil, err, errcode
   •

   ▷ name, version = rockspec.name, rockspec.version
   ⟦ repos.is_installed(name, version) ⟧
      repos.delete_version(name, version)
   •

   ⟦ ¬ minimal_mode ⟧
      ▷ _, source_dir
      ⟦ need_to_fetch ⟧
         ok, source_dir, errcode = fetch.fetch_sources(rockspec, true)
         ⟦ ¬ ok ⟧
            → nil, source_dir, errcode
         •
         fs.change_dir(source_dir)
      Ⅱ rockspec.source.file ⟧
         ▷ ok, err = fs.unpack_archive(rockspec.source.file)
         ⟦ ¬ ok ⟧
            → nil, err
         •
      •
      fs.change_dir(rockspec.source.dir)
   •

   ▷ dirs = {
      lua = { name = path.lua_dir(name, version), is_module_path = true },
      lib = { name = path.lib_dir(name, version), is_module_path = true },
      conf = { name = path.conf_dir(name, version), is_module_path = false },
      bin = { name = path.bin_dir(name, version), is_module_path = false },
   }

   ∀ _, d ∊ pairs(dirs) ⊢
      fs.make_dir(d.name)
   •
   ▷ rollback = util.schedule_fn(λ()
      fs.delete(path.install_dir(name, version))
      fs.remove_dir_if_empty(path.versions_dir(name))
   •)

   ▷ build = rockspec.build

   ⟦ ¬ minimal_mode ⟧
      ok, err = apply_patches(rockspec)
      ⟦ err ⟧
         → nil, err
      •
   •

   ⟦ build.type ≠ "none" ⟧

      -- Temporary compatibility
      ⟦ build.type == "module" ⟧
         util.printout("Do not use 'module' as a build type. Use
'builtin' instead.")
         build.type = "builtin"
      •

      ▷ build_type
      ok, build_type = pcall(require, "luarocks.build." · build.type)
      ⟦ ¬ ok ∨ ¬ type(build_type) == "table" ⟧
         → nil, "Failed initializing build back-end for build type
'"·build.type·"': "·build_type
      •

      ok, err = build_type.run(rockspec)
      ⟦ ¬ ok ⟧
         → nil, "Build error: " · err
      •
   •

   ⟦ build.install ⟧
      ∀ id, install_dir ∊ pairs(dirs) ⊢
         ok, err = install_files(build.install[id], install_dir.name,
install_dir.is_module_path)
         ⟦ ¬ ok ⟧
            → nil, err
         •
      •
   •

   ▷ copy_directories = build.copy_directories ∨ {"doc"}

   ∀ _, copy_dir ∊ pairs(copy_directories) ⊢
      ⟦ fs.is_dir(copy_dir) ⟧
         ▷ dest = dir.path(path.install_dir(name, version), copy_dir)
         fs.make_dir(dest)
         fs.copy_contents(copy_dir, dest)
      Ⅱ
         util.warning("Directory '"·copy_dir·"' not found")
      •
   •

   ∀ _, d ∊ pairs(dirs) ⊢
      fs.remove_dir_if_empty(d.name)
   •

   fs.pop_dir()

   fs.copy(rockspec.local_filename, path.rockspec_file(name, version))
   ⟦ need_to_fetch ⟧
      fs.pop_dir()
   •

   ok, err = manif.make_rock_manifest(name, version)
   ⟦ err ⟧ → nil, err •

   ok, err = repos.deploy_files(name, version,
repos.should_wrap_bin_scripts(rockspec))
   ⟦ err ⟧ → nil, err •

   util.remove_scheduled_fn(rollback)
   rollback = util.schedule_fn(λ()
      repos.delete_version(name, version)
   •)

   ok, err = repos.run_hook(rockspec, "post_install")
   ⟦ err ⟧ → nil, err •

   ok, err = manif.update_manifest(name, version, nil, deps_mode)
   ⟦ err ⟧ → nil, err •

   ▷ license = ""
   ⟦ rockspec.description ∧ rockspec.description.license ⟧
      license = ("(license: "·rockspec.description.license·")")
   •

   ▷ root_dir = path.root_dir(cfg.rocks_dir)
   util.printout()
   util.printout(name·" "·version·" is now built and installed in
"·root_dir·" "·license)

   util.remove_scheduled_λ(rollback)
   → true
•