<commit_before>#
# mal (Make a Lisp) object types
#

ifndef __mal_types_included
__mal_types_included := true

_TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(_TOP_DIR)gmsl.mk
include $(_TOP_DIR)util.mk
include $(_TOP_DIR)numbers.mk


# Low-level type implemenation

# magic is \u2344 \u204a
__obj_magic = ⍄⁊
# \u2256
__equal = ≛
__keyword = ʞ
__obj_hash_code = 0

__new_obj_hash_code = $(eval __obj_hash_code := $(call int_add,1,$(__obj_hash_code)))$(__obj_hash_code)

__new_obj = $(__obj_magic)_$(1)_$(call __new_obj_hash_code)

__new_obj_like = $(foreach type,$(word 2,$(subst _, ,$(1))),$(__obj_magic)_$(type)_$(__new_obj_hash_code))

__get_obj_values = $(strip \
                     $(if $(filter $(__obj_magic)_hmap_%,$(1)),\
                       $(sort $(foreach v,$(filter %_value,$(filter $(1)_%,$(.VARIABLES))),$(if $(call _undefined?,$(v)),,$(v)))),\
                       $($(1)_value)))


# Visualize Objects in memory
__var_name = $(word 2,$(subst _, ,$(1)))_$(word 3,$(subst _, ,$(1)))
__var_idx := 0
__var_print = $(foreach v,$(1),\
                $(foreach var,$(call __var_name,$(v)),\
                  $(if $(or $(call _list?,$(v)),$(call _vector?,$(v))),\
                    $(info $(2)$(var):)\
                    $(eval __var_idx := $(call int_add,1,$(__var_idx)))\
                    $(foreach lidx,__lidx_$(__var_idx),\
                      $(eval $(lidx) := 0)\
                      $(foreach val,$($(v)_value),\
                        $(call __var_print,$(val),$(2)$(SPACE)$(SPACE)$($(lidx)): )\
                        $(eval $(lidx) := $(call int_add,1,$($(lidx)))))),\
                  $(if $(call _hash_map?,$(v)),\
                    $(info $(2)$(var):)\
                    $(foreach vkey,$(filter $(v)_%,$(.VARIABLES)),\
                      $(foreach key,$(word 4,$(subst _, ,$(vkey))),\
                        $(info $(2)$(SPACE)$(SPACE)$(subst $(__equal),=,$(key)): )\
                        $(call __var_print,$($(vkey)),$(2)$(SPACE)$(SPACE)$(SPACE)$(SPACE)))),\
                  $(if $(call _symbol?,$(v)),\
                    $(info $(2)$(var): $($(v)_value)),\
                  $(if $(call _keyword?,$(v)),\
                    $(info $(2)$(var): $($(v)_value)),\
                  $(if $(call _number?,$(v)),\
                    $(info $(2)$(var): $(call int_decode,$($(v)_value))),\
                  $(if $(call _nil?,$(v)),\
                    $(info $(2)nil),\
                  $(if $(call _function?,$(v)),\
                    $(if $(word 6,$(value $(v)_value)),\
                      $(info $(2)$(var): $(wordlist 1,5,$(value $(v)_value))...),\
                      $(info $(2)$(var): $(value $(v)_value))),\
                  $(info $(2)$(var): ...))))))))))

_visualize_memory = $(foreach var,$(sort $(foreach vv,$(filter $(__obj_magic)_%,$(.VARIABLES)),$(call __var_name,$(vv)))),$(call __var_print,$(__obj_magic)_$(var)))


# Errors/Exceptions
__ERROR :=
_error = $(eval __ERROR := $(call _string,$(1)))


# Constant atomic values
__undefined = $(__obj_magic)_undf_0
__nil = $(__obj_magic)__nil_0
__true = $(__obj_magic)_true_0
__false = $(__obj_magic)_fals_0


# General functions

# Return the type of the object (or "make" if it's not a object
_obj_type = $(strip \
              $(if $(filter $(__obj_magic)_symb_%,$(1)),symbol,\
              $(if $(filter $(__obj_magic)_list_%,$(1)),list,\
              $(if $(filter $(__obj_magic)_numb_%,$(1)),number,\
              $(if $(filter $(__obj_magic)_func_%,$(1)),function,\
              $(if $(filter $(__obj_magic)_strn_%,$(1)),\
                $(if $(filter $(__keyword)%,$($(1)_value)),keyword,string),\
              $(if $(filter $(__obj_magic)__nil_%,$(1)),nil,\
              $(if $(filter $(__obj_magic)_true_%,$(1)),true,\
              $(if $(filter $(__obj_magic)_fals_%,$(1)),false,\
              $(if $(filter $(__obj_magic)_vect_%,$(1)),vector,\
              $(if $(filter $(__obj_magic)_atom_%,$(1)),atom,\
              $(if $(filter $(__obj_magic)_hmap_%,$(1)),hash_map,\
              $(if $(filter $(__obj_magic)_undf_%,$(1)),undefined,\
              make)))))))))))))

_clone_obj = $(strip \
               $(foreach new_hcode,$(call __new_obj_hash_code),\
                 $(foreach new_obj,$(foreach type,$(word 2,$(subst _, ,$(1))),$(__obj_magic)_$(type)_$(new_hcode)),\
                   $(if $(filter $(__obj_magic)_hmap_%,$(1)),\
                     $(foreach v,$(call __get_obj_values,$(1)),\
                       $(eval $(v:$(1)_%=$(new_obj)_%) := $($(v))))\
                     $(eval $(new_obj)_size := $($(1)_size)),\
                   $(if $(filter $(__obj_magic)_func_%,$(1)),\
                     $(eval $(new_obj)_value = $(value $(1)_value)),\
                     $(eval $(new_obj)_value := $(strip $($(1)_value)))))\
                   $(new_obj))))

_hash_equal? = $(strip \
                 $(if $(and $(call _EQ,$(foreach v,$(call __get_obj_values,$(1)),$(word 4,$(subst _, ,$(v)))),$(foreach v,$(call __get_obj_values,$(2)),$(word 4,$(subst _, ,$(v))))),\
                            $(call _EQ,$(call _count,$(1)),$(words $(call gmsl_pairmap,_equal?,$(foreach v,$(call __get_obj_values,$(1)),$($(v))),\
                                                                                               $(foreach v,$(call __get_obj_values,$(2)),$($(v))))))),\
                      $(__true),))

_equal? = $(strip \
            $(foreach ot1,$(call _obj_type,$(1)),$(foreach ot2,$(call _obj_type,$(2)),\
              $(if $(or $(call _EQ,$(ot1),$(ot2)),\
                        $(and $(call _sequential?,$(1)),$(call _sequential?,$(2)))),\
                $(if $(or $(call _string?,$(1)),$(call _symbol?,$(1)),$(call _keyword?,$(1)),$(call _number?,$(1))),\
                  $(call _EQ,$($(1)_value),$($(2)_value)),\
                $(if $(call _hash_map?,$(1)),\
                  $(call _hash_equal?,$(1),$(2)),\
                $(if $(or $(call _vector?,$(1)),$(call _list?,$(1))),\
                  $(if $(and $(call _EQ,$(call _count,$(1)),$(call _count,$(2))),\
                             $(call _EQ,$(call _count,$(1)),$(words $(call gmsl_pairmap,_equal?,$(call __get_obj_values,$(1)),\
                                                                                                $(call __get_obj_values,$(2)))))),\
                    $(__true),),\
                $(call _EQ,$(1),$(2)))))))))

_undefined? = $(or $(call _EQ,undefined,$(origin $(1))),$(filter $(__undefined),$($(1))))

_nil? = $(if $(filter $(__obj_magic)__nil_%,$(1)),$(__true),)

_true? = $(if $(filter $(__obj_magic)_true_%,$(1)),$(__true),)

_false? = $(if $(filter $(__obj_magic)_fals_%,$(1)),$(__true),)


# Symbols
_symbol = $(foreach hcode,$(call __new_obj_hash_code),$(__obj_magic)_symb_$(hcode)$(eval $(__obj_magic)_symb_$(hcode)_value := $(1)))
_symbol? = $(if $(filter $(__obj_magic)_symb_%,$(1)),$(__true),)


# Keywords
_keyword = $(foreach hcode,$(call __new_obj_hash_code),$(__obj_magic)_strn_$(hcode)$(eval $(__obj_magic)_strn_$(hcode)_value := $(__keyword)$(1)))
_keyword? = $(if $(filter $(__obj_magic)_strn_%,$(1)),$(if $(filter $(__keyword)%,$($(1)_value)),$(__true),))


# Numbers
_pnumber = $(foreach hcode,$(call __new_obj_hash_code),$(__obj_magic)_numb_$(hcode)$(eval $(__obj_magic)_numb_$(hcode)_value := $(1)))
_number = $(call _pnumber,$(call int_encode,$(1)))
_number? = $(if $(filter $(__obj_magic)_numb_%,$(1)),$(__true),)


# Strings<commit_msg>make: fix list comparison<commit_after>#
# mal (Make a Lisp) object types
#

ifndef __mal_types_included
__mal_types_included := true

_TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(_TOP_DIR)gmsl.mk
include $(_TOP_DIR)util.mk
include $(_TOP_DIR)numbers.mk


# Low-level type implemenation

# magic is \u2344 \u204a
__obj_magic = ⍄⁊
# \u2256
__equal = ≛
__keyword = ʞ
__obj_hash_code = 0

__new_obj_hash_code = $(eval __obj_hash_code := $(call int_add,1,$(__obj_hash_code)))$(__obj_hash_code)

__new_obj = $(__obj_magic)_$(1)_$(call __new_obj_hash_code)

__new_obj_like = $(foreach type,$(word 2,$(subst _, ,$(1))),$(__obj_magic)_$(type)_$(__new_obj_hash_code))

__get_obj_values = $(strip \
                     $(if $(filter $(__obj_magic)_hmap_%,$(1)),\
                       $(sort $(foreach v,$(filter %_value,$(filter $(1)_%,$(.VARIABLES))),$(if $(call _undefined?,$(v)),,$(v)))),\
                       $($(1)_value)))


# Visualize Objects in memory
__var_name = $(word 2,$(subst _, ,$(1)))_$(word 3,$(subst _, ,$(1)))
__var_idx := 0
__var_print = $(foreach v,$(1),\
                $(foreach var,$(call __var_name,$(v)),\
                  $(if $(or $(call _list?,$(v)),$(call _vector?,$(v))),\
                    $(info $(2)$(var):)\
                    $(eval __var_idx := $(call int_add,1,$(__var_idx)))\
                    $(foreach lidx,__lidx_$(__var_idx),\
                      $(eval $(lidx) := 0)\
                      $(foreach val,$($(v)_value),\
                        $(call __var_print,$(val),$(2)$(SPACE)$(SPACE)$($(lidx)): )\
                        $(eval $(lidx) := $(call int_add,1,$($(lidx)))))),\
                  $(if $(call _hash_map?,$(v)),\
                    $(info $(2)$(var):)\
                    $(foreach vkey,$(filter $(v)_%,$(.VARIABLES)),\
                      $(foreach key,$(word 4,$(subst _, ,$(vkey))),\
                        $(info $(2)$(SPACE)$(SPACE)$(subst $(__equal),=,$(key)): )\
                        $(call __var_print,$($(vkey)),$(2)$(SPACE)$(SPACE)$(SPACE)$(SPACE)))),\
                  $(if $(call _symbol?,$(v)),\
                    $(info $(2)$(var): $($(v)_value)),\
                  $(if $(call _keyword?,$(v)),\
                    $(info $(2)$(var): $($(v)_value)),\
                  $(if $(call _number?,$(v)),\
                    $(info $(2)$(var): $(call int_decode,$($(v)_value))),\
                  $(if $(call _nil?,$(v)),\
                    $(info $(2)nil),\
                  $(if $(call _function?,$(v)),\
                    $(if $(word 6,$(value $(v)_value)),\
                      $(info $(2)$(var): $(wordlist 1,5,$(value $(v)_value))...),\
                      $(info $(2)$(var): $(value $(v)_value))),\
                  $(info $(2)$(var): ...))))))))))

_visualize_memory = $(foreach var,$(sort $(foreach vv,$(filter $(__obj_magic)_%,$(.VARIABLES)),$(call __var_name,$(vv)))),$(call __var_print,$(__obj_magic)_$(var)))


# Errors/Exceptions
__ERROR :=
_error = $(eval __ERROR := $(call _string,$(1)))


# Constant atomic values
__undefined = $(__obj_magic)_undf_0
__nil = $(__obj_magic)__nil_0
__true = $(__obj_magic)_true_0
__false = $(__obj_magic)_fals_0


# General functions

# Return the type of the object (or "make" if it's not a object
_obj_type = $(strip \
              $(if $(filter $(__obj_magic)_symb_%,$(1)),symbol,\
              $(if $(filter $(__obj_magic)_list_%,$(1)),list,\
              $(if $(filter $(__obj_magic)_numb_%,$(1)),number,\
              $(if $(filter $(__obj_magic)_func_%,$(1)),function,\
              $(if $(filter $(__obj_magic)_strn_%,$(1)),\
                $(if $(filter $(__keyword)%,$($(1)_value)),keyword,string),\
              $(if $(filter $(__obj_magic)__nil_%,$(1)),nil,\
              $(if $(filter $(__obj_magic)_true_%,$(1)),true,\
              $(if $(filter $(__obj_magic)_fals_%,$(1)),false,\
              $(if $(filter $(__obj_magic)_vect_%,$(1)),vector,\
              $(if $(filter $(__obj_magic)_atom_%,$(1)),atom,\
              $(if $(filter $(__obj_magic)_hmap_%,$(1)),hash_map,\
              $(if $(filter $(__obj_magic)_undf_%,$(1)),undefined,\
              make)))))))))))))

_clone_obj = $(strip \
               $(foreach new_hcode,$(call __new_obj_hash_code),\
                 $(foreach new_obj,$(foreach type,$(word 2,$(subst _, ,$(1))),$(__obj_magic)_$(type)_$(new_hcode)),\
                   $(if $(filter $(__obj_magic)_hmap_%,$(1)),\
                     $(foreach v,$(call __get_obj_values,$(1)),\
                       $(eval $(v:$(1)_%=$(new_obj)_%) := $($(v))))\
                     $(eval $(new_obj)_size := $($(1)_size)),\
                   $(if $(filter $(__obj_magic)_func_%,$(1)),\
                     $(eval $(new_obj)_value = $(value $(1)_value)),\
                     $(eval $(new_obj)_value := $(strip $($(1)_value)))))\
                   $(new_obj))))

_hash_equal? = $(strip \
                 $(if $(and $(call _EQ,$(foreach v,$(call __get_obj_values,$(1)),$(word 4,$(subst _, ,$(v)))),$(foreach v,$(call __get_obj_values,$(2)),$(word 4,$(subst _, ,$(v))))),\
                            $(call _EQ,$(call _count,$(1)),$(words $(call gmsl_pairmap,_equal?,$(foreach v,$(call __get_obj_values,$(1)),$($(v))),\
                                                                                               $(foreach v,$(call __get_obj_values,$(2)),$($(v))))))),\
                      $(__true),))

_equal? = $(strip \
            $(foreach ot1,$(call _obj_type,$(1)),$(foreach ot2,$(call _obj_type,$(2)),\
              $(if $(or $(call _EQ,$(ot1),$(ot2)),\
                        $(and $(call _sequential?,$(1)),$(call _sequential?,$(2)))),\
                $(if $(or $(call _string?,$(1)),$(call _symbol?,$(1)),$(call _keyword?,$(1)),$(call _number?,$(1))),\
                  $(call _EQ,$($(1)_value),$($(2)_value)),\
                $(if $(call _hash_map?,$(1)),\
                  $(call _hash_equal?,$(1),$(2)),\
                $(if $(or $(call _vector?,$(1)),$(call _list?,$(1))),\
		  $(if $(and $(call _EQ,$(call _count,$(1)),$(call _count,$(2))),\
                             $(call _EQ,$(call _count,$(1)),$(words $(call gmsl_pairmap,_equal?,$(call __get_obj_values,$(1)),$(call __get_obj_values,$(2)))))),\
                    $(__true),),\
                $(call _EQ,$(1),$(2)))))))))

_undefined? = $(or $(call _EQ,undefined,$(origin $(1))),$(filter $(__undefined),$($(1))))

_nil? = $(if $(filter $(__obj_magic)__nil_%,$(1)),$(__true),)

_true? = $(if $(filter $(__obj_magic)_true_%,$(1)),$(__true),)

_false? = $(if $(filter $(__obj_magic)_fals_%,$(1)),$(__true),)


# Symbols
_symbol = $(foreach hcode,$(call __new_obj_hash_code),$(__obj_magic)_symb_$(hcode)$(eval $(__obj_magic)_symb_$(hcode)_value := $(1)))
_symbol? = $(if $(filter $(__obj_magic)_symb_%,$(1)),$(__true),)


# Keywords
_keyword = $(foreach hcode,$(call __new_obj_hash_code),$(__obj_magic)_strn_$(hcode)$(eval $(__obj_magic)_strn_$(hcode)_value := $(__keyword)$(1)))
_keyword? = $(if $(filter $(__obj_magic)_strn_%,$(1)),$(if $(filter $(__keyword)%,$($(1)_value)),$(__true),))


# Numbers
_pnumber = $(foreach hcode,$(call __new_obj_hash_code),$(__obj_magic)_numb_$(hcode)$(eval $(__obj_magic)_numb_$(hcode)_value := $(1)))
_number = $(call _pnumber,$(call int_encode,$(1)))
_number? = $(if $(filter $(__obj_magic)_numb_%,$(1)),$(__true),)


# Strings
{'fraction_non_alphanumeric': 0.24665676077265974, 'fraction_numerical': 0.015804403620153992, 'mean_word_length': 2.592188258127123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3043931', 'n_tokens_mistral': 5206, 'n_tokens_neox': 4962, 'n_words': 831}