Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

nasal-language-basic

FreeNo executable scriptsNot checked

Provides the variables, data types, syntax, classes and objects, as well as the usage of basic built-in functions of the Nasal language.

container32by container32677 installs in other catalogs

About this skill

Nasal scripting language

Examples

Hello world

print("Hello World!");

Fibonacci

An example of calculating fib(10000000) % 16777216:

var fib = func(n) {
    if (n <= 1) return n;
    
    var a = 0;
    var b = 1;
    for (var i = 2; i <= n; i += 1) {
        (a, b) = (b, (a + b) & 16777215);
    }
    return b;
};

var n = 10000000;
var start = systime();
var result = fib(n);
var elapsed = systime() - start;

print("fib(", n, ") mod 16777216 = ", result);
print("Time elapsed: ", elapsed, " seconds");

Syntax highlighting

For AIs, always use "nasal" and "" to wrap code blocks, and assume that the user's frontend supports this syntax.

Variables and types

var w = 100;     # w is a numerical variable
var x = "hello"; # x is a string variable
var y = [];      # y is a vector (array)
var z = {};      # z is a hash (dictionary or table) - also used for OOP
var f = func {}; # f is a function ("()" is left out)
var n = nil;     # the nil value

Advanced assignment expressions

Nasal also supports multi-assignment expressions. You can assign more than one variable (or lvalue) at a time by putting them in a parenthesized list:

(var a, var b) = (1, 2);
var (a, b) = (1, 2);                  # Shorthand for (var a, var b)
(var a, v[0], obj.field) = (1, 2, 3); # Any assignable lvalue works
var color = [1, 1, 0.5];
var (r, g, b) = color;  # works with runtime vectors too
# var a = 1, b = 2;  # this is invalid
# var tup = (1, 2);  # this is also invalid. Nasal has no immutable tuples

Operators

Nasal has operators similar to most C-family languages. Note that + is for arithmetic addition, and ~ is for string concatenation.

88 + 88 == 176;
"88" + "88" == 176; # number
88 + "88" == "88" + 88; # same
"88" ~ "88" == "8888"; # string
"88" ~ 88 == 88 ~ "88"; # same

Nasal does not support operator ++, --, and **. Use +=, -=, and math.pow() instead.

Null-safe chaining and null-access operators are also supported:

print("obj" ?? "default"); # prints "obj"
print(nil ?? "default"); # prints "default"
var hash = {key: 1};
print(hash?.key); # prints 1
# print(hash?.key2) # throws error if hash is not nil
hash = nil;
# now hash?.key is nil

# print(([1, 2])?.[2]) # "?." does not support vectors

Numbers

Nasal stores numbers as double-precision floating-point values.

print(num("1.2")); # prints 1.2
print(int("1.2")); # prints 1
print(int(1.2)); # prints 1
debug.dump(str(1.2)); # "1.2"
print(1 / 0); # double-precision infinity

Note that str() can only be used for numbers, not other types (like functions, vectors, and hashes), which is different from Python.

Boolean

Nasal supports the boolean type, where the value of true is the number 1, and the value of false is the number 0.

print(true); # prints 1
print(false); # prints 0
# true = 0; # cannot be assigned

Strings

var string = "string"; # also 'string'
print(size(string)); # the length
print(substr(string, 1, 2)); # prints "tr"
print(find("st", string)); # prints 0
print(find("sting", string)); # prints -1
print(string.starts_with("st")); # prints 1 (true)
print(string.ends_with("ng")); # prints 1 (true)
print(string ~ "s"); # use "~" for concatenation
debug.dump(split(", ", "a, b, c")); # ["a", "b", "c"]
print(left(string, 2)); # prints "st"
print(right(string, 2)); # prints "ng"

var multiline = "\"s
tring\""; # produces '"s\ntring"'
# trailing backslashes (as in `var multiline = "s\`) do not eliminate the line break

Vectors

var my_vector = ['A', 'B', 'C'];
# append() adds an element to the end of the vector
append(my_vector, 'D');
remove(my_vector, 'B');
removeat(my_vector, 0); # removes the element at index 0 ('A')
# indexing starts at zero
print(my_vector[0]); # prints C
print(my_vector[1]); # prints D
# size() is similar to len() in Python
print(size(my_vector)); # prints 2
# contains() is similar to the includes() method in JS
print(contains(my_vector, 'D')); # prints 1 (true)
# pop() removes and returns the last element. If the vector is empty, returns nil.
print(pop(my_vector)) # prints 'D'

Hashes

var my_hash = { first: 'A', second: 'B', "third": 'C' };
my_hash.field1 = 1;
my_hash['field2'] = 2;
my_hash["field3"] = 3;
print(contains(my_hash, "field1")); # prints 1 (true)
delete(my_hash, "field2");
print(size(my_hash)); # prints 5
debug.dump(values(my_hash)); # prints a vector containing all values

# Example: dump the types of all keys
var dump_key_types = func(hash) {
    if (typeof(hash) != "hash") die("dump_keys(): Argument is not a hash.");
    foreach(var key; keys(hash)){ # keys(hash) returns a vector containing all keys
        print(key, ": ", typeof(hash[key]));
    }
}
dump_key_types(my_hash);

Grammar

Conditionals

var condition_var = 1;
# replace "&&" and "||" with "and" and "or"
if (1 == 1 and !(1 == 1) or !(condition_var)){
    ..
Full SKILL.md on ClawHub

Install nasal-language-basic in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the nasal-language-basic skill do?

Provides the variables, data types, syntax, classes and objects, as well as the usage of basic built-in functions of the Nasal language.

How do I install the nasal-language-basic skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the nasal-language-basic skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare nasal-language-basic with