Skip to content

Commit

Permalink
cleaned up code section header, error checking for format-args
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Ward committed Aug 14, 2024
1 parent e5db8a4 commit 1e98bc5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/canary/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1177,19 +1177,19 @@
get_symbol_metatype(_Vl,'%Undefined%','Symbol').
get_symbol_metatype(_Vl,_Want,'Grounded').

as_metta_char(X,'#\\'(X)).

eval_20(Eq,RetType,Depth,Self,['stringToChars',String],Chars):- !, eval_args(Eq,RetType,Depth,Self,String,SS), string_chars(SS,Chars0), maplist(as_metta_char,Chars0,Chars).
eval_20(Eq,RetType,Depth,Self,['charsToString',Chars],String):- !, eval_args(Eq,RetType,Depth,Self,Chars,CC), maplist(as_metta_char,CC0,CC), string_chars(String,CC0).

% =================================================================
% =================================================================
% =================================================================
% FORMAT-ARGS
% STRINGS
% =================================================================
% =================================================================
% =================================================================

as_metta_char(X,'#\\'(X)).

eval_20(Eq,RetType,Depth,Self,['stringToChars',String],Chars):- !, eval_args(Eq,RetType,Depth,Self,String,SS), string_chars(SS,Chars0), maplist(as_metta_char,Chars0,Chars).
eval_20(Eq,RetType,Depth,Self,['charsToString',Chars],String):- !, eval_args(Eq,RetType,Depth,Self,Chars,CC), maplist(as_metta_char,CC0,CC), string_chars(String,CC0).

% We deal with indexing, but not formatting (the stuff following the ':')(yet)
% https://doc.rust-lang.org/std/fmt/ used as a reference

Expand Down Expand Up @@ -1227,10 +1227,14 @@
format_args(FormatRest3, Iterator2, Args).
format_args([C|FormatRest], Iterator, Args) :- put(C), format_args(FormatRest, Iterator, Args).

eval_20(Eq,RetType,Depth,Self,['format-args',Format,Args],Result):- !,
eval_20(Eq,RetType,Depth,Self,['format-args',Format,Args],Result):-
eval_args(Eq,RetType,Depth,Self,Format,EFormat),
eval_args(Eq,RetType,Depth,Self,Args,EArgs),
is_list(EArgs),string_chars(EFormat, FormatChars), user_io(with_output_to(string(Result), format_args(FormatChars, 0, EArgs))).
is_list(EArgs),string_chars(EFormat, FormatChars), !,
user_io(with_output_to(string(Result), format_args(FormatChars, 0, EArgs))).
eval_20(Eq,RetType,Depth,Self,['format-args',_Fmt,Args],_Result) :-
eval_args(Eq,RetType,Depth,Self,Args,EArgs),
\+ is_list(EArgs),!,throw_metta_return(['Error',Args,'BadType']).

eval_20(Eq,RetType,_Depth,_Self,['flip'],Bool):-
ignore(RetType='Bool'), !, as_tf(random(0,2,0),Bool),
Expand Down

0 comments on commit 1e98bc5

Please sign in to comment.