Skip to content

Commit

Permalink
Merge branch 'release/1.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sheikhartin committed Mar 27, 2024
2 parents b12705c + fd4fc8b commit 71f4d0a
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 63 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### [1.4.2](https://github.com/sheikhartin/farr/releases/tag/1.4.2)

Moving the algorithms library to the [examples](examples) folder.

### [1.4.1](https://github.com/sheikhartin/farr/releases/tag/1.4.1)

A hotfix for interpreting arguments before creating a new environment!

### [1.4.0](https://github.com/sheikhartin/farr/releases/tag/1.4.0)

Enhancements and new features in invocation and operations:
Expand Down
37 changes: 37 additions & 0 deletions examples/binary_search/sol01.farr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Binary search efficiently locates an item in a sorted sequence by
* repeatedly dividing the search interval in half. If the target is less than
* the item in the middle, the search continues in the lower half, otherwise
* in the upper half, until the item is found or the search space is empty.
*/

use math/random;

fn binary_search(let list, let target) = {
let left = 1;
let right = list.length;

while left <= right = {
let mid = (+ / - right left 2 left).toint();
let result = list.[mid];

if result < target = {
left = + mid 1;
} else if result > target = {
right = - mid 1;
} else = {
return! mid;
}
}

return! -1;
}

let nums = random.randint(0, 50, size=10);
let goal = (
readln!("What is your goal number? ")
.toint()
);

println("Generated numbers: ${nums}");
println("Does it exist? ${binary_search(nums, goal)}");
26 changes: 26 additions & 0 deletions examples/bubble_sort/sol01.farr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Bubble sort is a simple sorting algorithm that repeatedly steps through
* the list, compares adjacent elements and swaps them if they are in
* the wrong order. This process is repeated until the list is sorted.
*/

use math/random;

fn bubble_sort(let list) = {
let length = list.length;
for let i in [1..length] = {
for let j in [1..- length i] = {
if list.[j] > list.[+ j 1] = {
let tmp = list.[j];
list.[j] = list.[+ j 1];
list.[+ j 1] = tmp;
}
}
}
return! list;
}

let nums = random.randint(0, 50, size=10);

println("Before sorting: ${nums}");
println("After sorting: ${bubble_sort(nums)}");
2 changes: 1 addition & 1 deletion farr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

__author__ = 'Artin Mohammadi <[email protected]>'
__license__ = 'MIT'
__version__ = '1.4.0'
__version__ = '1.4.2'
12 changes: 12 additions & 0 deletions farr/interpreter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ def _populate_params(
raise TypeError(
'Not enough arguments provided for the required parameters.'
)
elif len(args_) > len(required) and not variadic:
raise TypeError(
'Provided more positional arguments than the function accepts.'
)
elif not args_ and not exp_args and required:
raise TypeError('Required parameters are missing arguments.')
elif (args_ or exp_args) and not required and optional:
Expand All @@ -371,6 +375,14 @@ def _populate_params(
raise TypeError(
'Keyword arguments provided but the function does not accept them.'
)
elif kwargs and set(
map(lambda x: x.references.items[0].value, kwargs)
).isdisjoint(map(lambda x: x.identifier.value, optional)):
raise TypeError(
'Provided keyword arguments do not correspond to any optional '
'parameters. Please check the function definition for valid '
'parameter names.'
)
elif len(variadic) > 1:
raise TypeError(
'Multiple variadic parameters defined. '
Expand Down
1 change: 0 additions & 1 deletion libs/algorithms/funda.farr

This file was deleted.

42 changes: 0 additions & 42 deletions libs/algorithms/searching.farr

This file was deleted.

18 changes: 0 additions & 18 deletions libs/algorithms/sorting.farr

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "farr"
version = "1.4.0"
version = "1.4.2"
description = "The gathering place of utilitarians and empiricists!"
license = "MIT"
authors = ["Artin Mohammadi <[email protected]>"]
Expand Down

0 comments on commit 71f4d0a

Please sign in to comment.