NOW LET US – AI RAG SaaS Studio TP.HCM
NOW LET US
Digital Product Studio
Back to news
DEV-TOOLS...2 min read

Rubysyn: Clarifying Ruby's Syntax and Semantics

Share
NOW LET US Article – Rubysyn: Clarifying Ruby's Syntax and Semantics

Rubysyn is an experimental project that introduces a Lisp-based syntax for Ruby to clarify its complex semantics and remove syntactic sugar.

[WIP, 2026-04-01] This is an experiment in clarifying some aspects of Ruby syntax and semantics. For that we're going to introduce an alternative Lisp-based syntax for Ruby, preserving Ruby semantics.

The goal is to define a comprehensive, trivially-parsable and sugar-free syntax.

As I started working on this, I had to find a better explanation for some aspects of Ruby than what is available in standard documentation. So we also discuss some aspects of standard Ruby syntax and semantics.

See the spec/ directory for some corner cases of Ruby syntax and semantics that we are interested here.

Table of Contents

  • Array literals: full version
  • Single-variable assignment
  • Multi-variable assignment
  • Logical operators
  • Semantic primitives
  • Control flow
  • Blocks and lambdas
  • Classes, modules and methods
  • Rubysyn: literals

For some reason, the standard documentation does not explain full syntax of array literals.

Most common case of array literals is extremely well known:

  • empty array: [];
  • array of three elements: [1, 2, 3];
  • string-array literals: %w(...) and %W(...);
  • symbol-array literals: %i(...) and %I(...);

Additionally, array literals support so called "constructing array splat" syntax: [1, 2, *foo, 3]

The asterisk before the value replaces it with zero or more values, depending on what is in foo:

  • if foo is an array, *foo is replaced by its elements:
foo = [10, 11]
[1, 2, *foo, 3]
# [1, 2, 10, 11, 3]
  • if foo responds to to_a method, that method is called, and *foo is replaced by the result array;
  • finally, for all other values *foo is replaced by the value of foo:
foo = "hello"
[1, 2, *foo, 3]
# [1, 2, "hello", 3]

Particularly, nil.to_a returns an empty array:

foo = nil
[1, 2, *foo, 3]
# [1, 2, 3]

If foo is a hash, *foo is replaced by a list of two-element arrays, one for each hash key:

foo = { foo: :bar, quux: 23 }
[1, 2, *foo, 3]
# [1, 2, [ :foo, :bar ], [ :quux, 23 ], 3]

Constructing array splat is pure syntactic sugar. You can easily implement it as a simple Ruby function:

def array_splat(arr, chunk)
  case
  when chunk.is_a?(Array)
    return arr.concat(chunk)
  when chunk.respond_to?(:to_a)
    tmp = chunk.to_a
    if tmp.is_a?(Array)
      return arr.concat(tmp)
    else
      raise TypeError.new("can't convert #{chunk.class} to Array")
    end
  else
    return arr.append(chunk)
  end
end

Single-variable assignment has a very simple base syntax: a = 3. Variable assignment automatically declares variable in the current binding, if it was not already declared. Newly-declared variables have a value of nil.

In Rubysyn, we decouple variable declaration from variable assignment:

  • (var <var>): Declares variables and initializes them to nil.
  • (assign var value): Assigns a single value to a single variable.

Multi-variable assignment: a, b, c = 1, 2, 3. On the left side of assignment operator (=) there is a list of two or more variable names. One, and only one variable on the left hand side could be marked with a special "*" (asterisk) syntax. This variable will get assigned an array value that contains all values left after other variables are assigned.

© 2026 Now Let Us. All rights reserved.

Source: Hacker News

Advertisement
Ad slot ready: 5887729102

More in this category

NOW LET US Related – GLM 5.2 Is Out

dev-tools

GLM 5.2 Is Out

Zhipu AI has officially released GLM-5.2, its most powerful open-source model to date, featuring a 1M context window and advanced long-horizon task capabilities. The release underscores Zhipu's commitment to open-source AI and global scientific collaboration amid rising technological restrictions.

NOW LET US Related – Noise infusion banned from statistical products published by Census Bureau

dev-tools

Noise infusion banned from statistical products published by Census Bureau

The U.S. Department of Commerce has banned "noise infusion" from statistical products published by the Census Bureau, a decision that could have severe consequences for both data utility and privacy protection.

NOW LET US Related – Treating pancreatic tumours may have revealed cancer's master switch

dev-tools

Treating pancreatic tumours may have revealed cancer's master switch

A promising new drug called daraxonrasib has shown breakthrough results in treating pancreatic cancer, doubling median survival times. This achievement could pave the way for an entirely new class of cancer treatments.

NOW LET US Related – Every Frame Perfect

dev-tools

Every Frame Perfect

In UI design, perfection isn't just about the start and end states, but every single transition frame in between. Polishing these micro-interactions is key to building user trust.

NOW LET US Related – Leaving Mozilla

dev-tools

Leaving Mozilla

A poignant and candid reflection from a 15-year Mozilla veteran upon their departure. The author highlights the leadership's missteps in trying to emulate tech giants and urges Mozilla to return to its core values: community and uniqueness.

NOW LET US Related – Shepherd's Dog: A Game by the Most Dangerous AI Model

dev-tools

Shepherd's Dog: A Game by the Most Dangerous AI Model

A developer tested Anthropic's latest, supposedly 'too dangerous' AI model by asking it to build a long-held game idea in a single shot. The model succeeded, generating a complete 2,319-line game after a 45-minute reasoning session.

EXPLORE TOPICS

Discover All Categories

Deep dive into the specific technology sectors that matter most to you.