Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion izia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
let reader = Interface::new("IZia").unwrap();
println!("IZia Copyright (C) 2018 to 2019 Charles Johnson.\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain\nconditions; visit https://www.gnu.org/licenses/gpl-3.0.en.html for more details.");
reader.set_prompt(">>> ").unwrap();
let mut cont = Context::new().unwrap();
let mut cont = Context::new();
while let ReadResult::Input(input) = reader.read_line().unwrap() {
println!("{}", cont.execute(&input));
}
Expand Down
2 changes: 1 addition & 1 deletion presentations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn main() {
});
}
}
let mut context = Context::new().unwrap();
let mut context = Context::new();
for command in commands {
context.execute(&command);
}
Expand Down
4 changes: 2 additions & 2 deletions zia-lang.org/crate/src/page/home/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Model {
impl Default for Model {
fn default() -> Self {
Self {
context: Context::new().unwrap(),
context: Context::new(),
input: String::new(),
history: Vec::new(),
command_input: ElRef::new(),
Expand All @@ -39,7 +39,7 @@ impl Default for Model {

impl Model {
fn reset(&mut self) {
self.context = Context::new().unwrap();
self.context = Context::new();
self.history = Vec::new();
self.menu.is_open = false;
}
Expand Down
20 changes: 19 additions & 1 deletion zia-lang.org/crate/src/page/home/tutorials.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
use std::time::{Duration, Instant};

pub const TUTORIALS: (Tutorial<18>, Tutorial<10>, Tutorial<12>) = (
pub const TUTORIALS: (Tutorial<18>, Tutorial<12>, Tutorial<12>) = (
Tutorial {
title: "Factorial",
steps: [
Expand Down Expand Up @@ -178,6 +178,24 @@ pub const TUTORIALS: (Tutorial<18>, Tutorial<10>, Tutorial<12>) = (
#[cfg(test)]
expected_evaluation: "true"
},
TutorialStep {
command: "let ((_y_ exists_such_that) (_y_ is parent of _x_) and (_y_ is parent of _z_)) => (_x_ is sibling of _z_)",
explanation: "Define sibling is terms of parent relationships",
#[cfg(test)]
expected_evaluation: ""
},
TutorialStep {
command: "let Alice is parent of Eve",
explanation: "This should mean that Eve is sibling of Bob",
#[cfg(test)]
expected_evaluation: ""
},
//TutorialStep {
// command: "Eve is sibling of Bob",
// explanation: "Let's check",
// #[cfg(test)]
// expected_evaluation: "true"
//}
]
},
Tutorial {
Expand Down
2 changes: 1 addition & 1 deletion zia/src/ast/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<CI: ConceptId, SR: SharedReference> GenericSyntaxTree<CI, SR> {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct SyntaxKey<CI: ConceptId> {
syntax: Option<String>,
concept: Option<CI>,
pub concept: Option<CI>,
}

impl<CI: ConceptId, SR: SharedReference> PartialEq<Self>
Expand Down
17 changes: 15 additions & 2 deletions zia/src/concepts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use crate::{
};
use maplit::{hashmap, hashset};
use std::{
collections::{hash_map::Iter, HashMap, HashSet},
collections::{
hash_map::{IntoIter, Iter},
HashMap, HashSet,
},
fmt::{Debug, Display},
hash::Hash,
iter::{Copied, Map},
Expand Down Expand Up @@ -441,6 +444,7 @@ impl<'a, Id: Copy + Debug + Eq + Hash> From<&'a NewDirectConceptDelta<Id, Id>>
type CopyPairFn<T> = fn((&T, &T)) -> (T, T);

type CopiedPairIter<'a, T> = Map<Iter<'a, T, T>, CopyPairFn<T>>;
type OwnedPairIter<T> = IntoIter<T, T>;

impl<Id: Copy + Display + Eq + Hash + Debug + 'static> ConceptTrait
for Concept<Id>
Expand All @@ -449,6 +453,7 @@ impl<Id: Copy + Display + Eq + Hash + Debug + 'static> ConceptTrait
type IdIterator<'a> =
Copied<std::collections::hash_set::Iter<'a, Self::Id>>;
type IdPairIterator<'a> = CopiedPairIter<'a, Self::Id>;
type OwnedIdPairIterator = OwnedPairIter<Self::Id>;

fn id(&self) -> Id {
self.id
Expand Down Expand Up @@ -702,6 +707,14 @@ impl<Id: Copy + Display + Eq + Hash + Debug + 'static> ConceptTrait
.iter()
.map(copy_pair_elements)
}

fn into_iter_hand_of(self, hand: Hand) -> Self::OwnedIdPairIterator {
match hand {
Hand::Left => self.concrete_part.lefthand_of,
Hand::Right => self.concrete_part.righthand_of,
}
.into_iter()
}
}

const fn copy_pair_elements<T: Copy>((x, y): (&T, &T)) -> (T, T) {
Expand All @@ -719,7 +732,7 @@ pub enum SpecificPart<Id: Eq + Hash> {
String(String),
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum Hand {
Left,
Right,
Expand Down
13 changes: 13 additions & 0 deletions zia/src/concepts/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub trait Concept: Sized {
type IdIterator<'a>: Iterator<Item = Self::Id>
where
Self: 'a;
type OwnedIdPairIterator: Iterator<Item = (Self::Id, Self::Id)> + 'static;
fn id(&self) -> Self::Id;

fn maybe_composition(&self) -> Option<MaybeComposition<Self::Id>>;
Expand Down Expand Up @@ -103,8 +104,20 @@ pub trait Concept: Sized {
}
self.iter_hand_of(hand).map(f::<Self::Id>)
}
fn into_iter_composition_ids(
self,
hand: Hand,
) -> Map<Self::OwnedIdPairIterator, SelectElementFromPairFn<Self::Id>> {
// the argument is dropped in the function but destructors cannot run in const contexts
#[allow(clippy::missing_const_for_fn)]
fn f<Id>(p: (Id, Id)) -> Id {
p.1
}
self.into_iter_hand_of(hand).map(f::<Self::Id>)
}

fn iter_hand_of(&self, hand: Hand) -> Self::IdPairIterator<'_>;
fn into_iter_hand_of(self, hand: Hand) -> Self::OwnedIdPairIterator;

/// Gets the index of the concept that `self` may reduce to.
fn get_reduction(&self) -> Option<Self::Id>;
Expand Down
Loading
Loading