Skip to content

Commit

Permalink
Merge pull request #75 from royward/main
Browse files Browse the repository at this point in the history
format-args improvements
  • Loading branch information
TeamSPoon authored Aug 15, 2024
2 parents 3d806de + e2f442b commit ab988d3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions .Attic/metta_lang/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,11 +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),
string_chars(EFormat, FormatChars), user_io(with_output_to(string(Result), format_args(FormatChars, 0, EArgs))).
% string_chars(EFormat, FormatChars), wots(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 ab988d3

Please sign in to comment.