├── bin ├── 2022mar13 │ └── tmp.lst ├── 2024dec22 │ ├── dat │ │ ├── j │ │ │ ├── 1 │ │ │ └── 2 │ │ ├── alpha.data │ │ ├── key_test_4_bruce.dat │ │ └── split_to_sigiless.dat │ ├── stupid_perl_trick.pl │ ├── running_raku_method_on_raku_output.raku │ └── split_to_sigiless.raku ├── 2021may02 │ ├── hello.raku │ └── hello-dpchrist ├── 2023jul23 │ ├── bg_wc.png │ ├── bg_wc2.png │ ├── bg_wc3.png │ ├── bg_wc4.png │ ├── hash_keys_with_spaces.raku │ ├── collisions_with_unsigiled_containing_callable.raku │ └── diving_ints_gets_you_type_of.raku ├── 2023sep10 │ ├── marton.png │ ├── marton-01.png │ ├── bruce_challenge_233.png │ ├── bruce_challenge_233-01.png │ └── command_line_options.raku ├── Subtitles │ ├── data │ │ ├── The_Judge_From_Hell-ep02.srt │ │ ├── The_Judge_From_Hell-ep02.mp4 │ │ ├── notes-the_judge_from_hell │ │ └── short.srt │ └── .META ├── 2023dec03 │ ├── bg_stuff-01.png │ ├── bg_stuff-02.png │ ├── ranges_of_points_kindof.raku │ ├── mark_a_question_match_warning.raku │ └── mkdir.raku ├── 2023dec17 │ └── rob_num_quotes.png ├── 2024may05 │ └── data │ │ └── issue_423.dat ├── 2024jul28 │ └── .META ├── 2022nov06 │ ├── participants_diehards.png │ ├── marton_code_odd_idioms.png │ ├── marton_polgar_code_ex-01.png │ └── marton_code_idioms_cartesian_set_diff.png ├── 2022nov20 │ ├── robs_decontainerizng_table.png │ ├── messing_with_quote_immutable_strings.raku │ ├── bags_of_lists.raku │ └── raku_hashes_compared_to_perl.raku ├── 2023mar26 │ ├── marton_example_rotor_on_lh.png │ ├── tr_and_multi_string_substitutions-01.png │ ├── assigning_nil.raku │ └── william_michaels_identity.raku ├── leland_numbers_inventing_new_operators.pl6 ├── 2022feb27 │ ├── bruce_gray_weekly_challenge-01.png │ ├── isolated_file_list_assigned_to_scalar.raku │ ├── rob_classify_issue.raku │ └── issue_4805_explorations.raku ├── 2025jun22 │ └── ord_demo.raku ├── .rep │ ├── 2021jan24-substitution_returns_a_match.pl6-22718-HAS.bak │ └── substitutions-22718-BHM.rep ├── 2023jul09 │ └── slurpy_script.raku ├── 2025jul13 │ ├── oddity_again.raku │ ├── trig_on_arrays.raku │ └── duckmap_sigs.raku ├── 2024apr07 │ ├── dat │ │ ├── index.csv │ │ └── data.csv │ └── subset_columns.raku ├── 2024apr21 │ └── dat │ │ ├── index.csv │ │ └── data.csv ├── 2022jul10 │ ├── se.awk │ └── anonymous_hash_intermediary.raku ├── 2024aug25 │ ├── messing_with_ranges.raku │ ├── ranges_positional.raku │ └── pi_mah_e.raku ├── 2024sep22 │ ├── array_operators.raku │ └── dollar_self.raku ├── 2022apr10 │ ├── dat │ │ └── so.dat │ └── bills_so_yaml_key_fusion.raku ├── 2023apr16 │ ├── unixstackexchange_fortran_d_to_scientific_e_and_filter_awk.sh │ ├── unixstackexchange_fortran_d_to_scientific_e_and_filter-bg.raku │ ├── unixstackexchange_fortran_d_to_scientific_e_and_filter-ii.raku │ ├── unixstackexchange_fortran_d_to_scientific_e_and_filter_wm_raku_oneliner.sh │ ├── rir_question_array_interpolation_in_quoted_strings.raku │ ├── ue.data │ └── unixstackexchange_fortran_d_to_scientific_e_and_filter.raku ├── 2025oct05 │ ├── missing_semi_eat_next_line.raku │ └── sub_as_method.raku ├── 2024oct20 │ ├── assigning_crap_to_ratoverflow.raku │ ├── fatrat_new.raku │ ├── assigning_crap_to_ratoverflow-i.raku │ ├── visibility_dynamics-ii.raku │ ├── visibility_dynamics.raku │ ├── rats_scraping_the_barrel.raku │ ├── visibility_dynamics-iii.raku │ ├── array_typology.raku │ ├── rat_docs.raku │ └── calculations_assigned_to_rats_and_fatrats.raku ├── 2024jun30 │ ├── laziness7.raku │ ├── laziness4.raku │ ├── laziness5.raku │ ├── laziness6.raku │ ├── shitov_variant_via_tim.raku │ ├── non_numeric_ranges.txt │ └── laziness2.raku ├── 2021dec05 │ └── bg_example_subs.raku ├── 2024feb25 │ ├── revisiting_lta_dropped_comma_on_say_array.raku │ ├── revisiting_lta_dropped_comma_on_say_hash.raku │ └── fussy_uint.raku ├── 2022mar27 │ ├── hendrix_numbers-02-bruce_gray.raku │ ├── tr.raku │ ├── comb.raku │ ├── werewolf_primes-02-via_perl_phasehunt_fullmoon_script.raku │ └── hendrix_numbers-01.raku ├── 2025aug10 │ ├── count_by_3.raku │ ├── hm.raku │ ├── ranges_and_sequences_oh_my.raku │ ├── infinite_sequence.raku │ ├── seq_exhaustion_change.raku │ ├── ranges_and_sequences-list_slices.raku │ ├── slipping_ranges_etc.raku │ └── ranges_and_sequences_glued_in_array_indexes.raku ├── 2022oct23 │ ├── funkiness.raku │ └── modgrid │ │ ├── jb_modgrid_01.raku │ │ └── jb_modgrid_02.raku ├── 2025dec07 │ ├── seq_vs_range_array_assign.raku │ └── spy_sub_as_method.raku ├── 2022jun19 │ ├── dat │ │ └── data_by_dates.txt │ ├── raku │ └── controlling_range_of_regex_capture_without_named_regex.raku ├── 2023mar05 │ ├── proc_simpler_call.raku │ ├── json_comparator_bruce_gray.raku │ ├── bg_inline_perl5_code_ref.raku │ └── json_comparator_worthington.pl6 ├── 2023apr30 │ ├── multiline_records.raku │ ├── data │ │ ├── nutrients_merelo.csv │ │ └── addresses.txt │ ├── jj_merelo_grep_csv.raku │ ├── jj_merelo_grep_csv-text_csv.raku │ └── dummy.pl ├── 2024may19 │ ├── introspection_sub_name.raku │ └── powers_of_two ├── 2025sep07 │ ├── silly_ex.raku │ ├── pick_roll_etc.raku │ ├── spurts_come_in_love.raku │ ├── redoing_bill2.raku │ └── datetime_37.raku ├── 2021feb14 │ ├── creating_hashes-variations_on_theme_by_lizmat.pl6 │ └── spy_via_ampersand.pl6 ├── 2024jul14 │ ├── quoting_error.raku │ ├── quoting_etc.raku │ └── multidispatch-01.raku ├── 2025jun08 │ └── old_smartmatch_behavior.raku ├── 2021jun20 │ ├── give_em_enough_rop.raku │ ├── trailing_if.raku │ ├── ternaryism.raku │ ├── element_membership.raku │ ├── junctionism.raku │ ├── function_composition_op.raku │ └── elisp_conditionals.el ├── 2022jan30 │ └── getting_hyper.raku ├── 2021apr25 │ ├── verifying_failure_is_false.raku │ ├── bg_stuff.raku │ ├── bg_idiom_assign_and_check_what_you_got.raku │ └── dd.raku ├── 2022jan16 │ ├── alternate_approach_ch2.raku │ └── crossproduct_metaoperator.raku ├── 2025apr13 │ └── old_q_regexp_objects_built_from_list.raku ├── 2021sep26 │ ├── csv.raku │ ├── is_it_an_list_maybe.raku │ ├── anon_var_vs_topic.raku │ ├── hailstone_numbers.raku │ └── multi_dispatch_int_collision.raku ├── 2023sep24 │ └── dat │ │ ├── issue_34_truncated.csv │ │ ├── issue_34.csv │ │ ├── issue_34_raw.csv │ │ └── issue_34_bills_truncs.csv ├── 2021aug15 │ ├── trial-spy_via_ampersand.pl6 │ └── bruce_gray_io_lines_etc.raku ├── 2021oct24 │ ├── try_and_fallback.raku │ ├── try_catch_basics.raku │ ├── raku_code_ex_generic_case.raku │ ├── docs_try_catch_ex.raku │ └── given_when_vs_passing_to_block.raku ├── 2025nov02 │ └── dat │ │ └── simple.org ├── DataCook │ └── data_joins.raku ├── 2025aug24 │ ├── bg.raku │ ├── literal_list_array_indicies.raku │ └── backward_ranges_empty_sets.raku ├── 2023dec31 │ └── rotor.raku ├── 2022dec18 │ ├── bool_value_of_zero.raku │ ├── negatives_not_lexically_literal.raku │ └── prompt_returns_what.raku ├── DeepMap │ ├── zip_redux.raku │ ├── disassemble_hash_reassemble_into_copy.raku │ └── hash_gyrations.raku ├── MultiDispatch │ ├── older_the_i_rule-doesnt_rule.raku │ ├── the_i_rule-doesnt_rule.raku │ ├── .META │ ├── broken_a_is_for_arity.raku │ ├── a_is_for_arity.raku │ └── num_types.raku ├── 2022oct09 │ └── trailing_bracket_sans_semicolon.raku ├── reduction_metaoperators.pl6 ├── 2025jan05 │ ├── sigiless.raku │ ├── sigil_divisor.raku │ ├── third_max.raku │ └── rw_var.raku ├── issues_3851_native_call_and_c_ints.pl6 ├── 2024jan21 │ ├── random_experiment_with_binding_to_hash.raku │ ├── basics_of_match_object.raku │ └── bruce_gray_wants_hashes_that_repel_changes_but_allow_dupes.raku ├── 2024nov24 │ ├── but_why.raku │ ├── roll_your_own_dynamic_var.raku │ └── min_max_of_arrays.raku ├── 2025may25 │ └── run_and_call_etc.raku ├── 2023oct22 │ ├── can_has_cool.raku │ └── samemark.raku ├── 2024mar10 │ ├── bruce_sort_naturally.raku │ └── toddandmargo_sort.raku ├── 2025apr27 │ └── smiley_sigs.raku ├── catching_errors_converting_to_warning.pl6 ├── 2021oct10 │ └── anon_var_vs_topic.raku ├── 2023may21 │ └── range_bounds_method.raku ├── 2024feb04 │ └── subs_and_passing_to_generic_array_at_underscore.raku ├── modulus_operators.pl6 ├── 2023aug06 │ ├── hash_definition_quirks.raku │ └── messing.raku ├── 2021jan24 │ ├── grammar_example_from_tutorial-poor_thor_is_mighty.pl6 │ ├── substitution_returns_a_match.pl6 │ └── grammar_calculator_example.pl6 ├── 2022jul24 │ ├── gather.raku │ └── matches_dollar_parens_addsign_hyper.raku ├── 2021jul11 │ └── exporting_a_sub.raku ├── json_comparator_worthington.pl6 ├── 2021sep12 │ ├── pandigital_prime_rosettacode.pl6 │ └── sum_of_primes_in_odd_positions_is_prime.pl6 ├── 2021feb07 │ └── reduction_over_iteration.pl6 ├── 2022jan02 │ ├── shitov_rotate_example.raku │ └── bruce_gray_example_custom_associative.raku ├── 2021mar21 │ ├── parsing_quoted_strings.raku │ └── parsing_quoted_strings_backslash.raku ├── 2024dec08 │ ├── try_again.raku │ └── bruce_gray_monkey_augment_str_upgraderat_etc.raku ├── 2022apr24 │ └── cool_object_fields.raku ├── 2021apr11 │ └── raku_dualvars_via_but.raku ├── 2023jun04 │ └── operator_introspection.raku ├── 2022aug07 │ ├── rob_using_topic_vs_named_var.raku │ └── given_with_topic.raku ├── 2025feb23 │ └── forcing_type_from_list_of_numbers.raku ├── 2024mar24 │ ├── digit_sum.raku │ └── enum_with_an_x.raku ├── 2022may08 │ ├── are.raku │ └── item.raku ├── 2023jan01 │ └── dpchrist_p5_threaded_code.pl ├── 2025jul27 │ └── matrix_add_on_two_vectors.raku ├── 2021apr18 │ ├── ignoremark.raku │ └── slurpy_array_param.raku ├── boolean_conversion_operator.pl6 ├── 2021mar28 │ └── first_method_on_arrays.raku ├── 2021jan31 │ └── rotate.pl6 ├── 2021aug29 │ ├── lca_so_3.raku │ └── so_question_order_of_operations_with_R_and_pop.raku ├── 2022aug21 │ └── 02-twiddle_vars.raku ├── 2022sep25 │ ├── arrays_with_sigils_and_without.raku │ └── smartmaching_arrays_lists.raku ├── 2025apr06 │ └── deep_and_ducks_and_rows.raku ├── 2022jun05 │ └── comma_equals_of_doom.raku ├── 2021nov07 │ └── junctions_sans_petticoats.raku ├── 2021mar14 │ └── find_palindrome_words.raku ├── the_dreaded_leland_number_golf_castrophe.pl6 └── 2021may30 │ └── crossproduct_operator_slash_x_etc.raku ├── t ├── dat │ ├── tree1.BAK │ │ ├── beta.txt │ │ ├── alpha.txt │ │ ├── gamma.txt │ │ └── son1 │ │ │ ├── aaa.txt │ │ │ ├── bbb.txt │ │ │ └── ccc.txt │ └── tree1_original.tar.gz ├── PlusMine │ └── dat │ │ ├── tree1.BAK │ │ ├── alpha.txt │ │ ├── beta.txt │ │ ├── gamma.txt │ │ └── son1 │ │ │ ├── aaa.txt │ │ │ ├── bbb.txt │ │ │ └── ccc.txt │ │ └── tree1_original.tar.gz ├── Tagger │ └── dat │ │ ├── tree1.BAK │ │ ├── alpha.txt │ │ ├── beta.txt │ │ ├── gamma.txt │ │ └── son1 │ │ │ ├── aaa.txt │ │ │ ├── bbb.txt │ │ │ └── ccc.txt │ │ └── tree1_original.tar.gz └── Deepmap │ └── deepmap_preserve_untouched_hash_elements.t ├── dat ├── some_hebrew.txt └── doomfiles │ └── README ├── notes ├── rob-01.png ├── rob-02.png ├── bg_squareful.png ├── hyperrob-01.png ├── rob_code_touch.png ├── bg_subset_with_bags.png ├── bg-01-use_of_repeated.png ├── etc │ ├── 01-jj_merelo_cookbook.jpg │ └── 02-jj_merelo_cookbook.jpg ├── BruceGrayDataRecordRole │ ├── bg-01.png │ ├── bg-02.png │ ├── bg-03.png │ └── bg-04.png ├── bg-weekly_challenger_none_divis_by_2.png ├── rob_squareful_range_windowing_array.png ├── bg_challenge_long_year_and_lychrel │ ├── bg-01.png │ ├── bg-02.png │ └── bg-02a.png ├── dpchrist-perl-walk │ ├── Dpchrist-Perl-walk-flowchart.odg │ └── Dpchrist-Perl-walk-flowchart.pdf ├── Week_Challenge-Moebius-Farey-etc │ ├── bruce_gray_wc_158-cu2-01.png │ ├── bruce_gray_cuban_primes-01.png │ ├── bruce_gray_wc_158_perl-01.png │ ├── bruce_gray_farey_sequence-01.png │ ├── bruce_gray_moebius_number-01.png │ ├── bruce_gray_moebius_number-02.png │ ├── bruce_gray_wc_158-cu2_perl-03.png │ ├── bruce_gray_wc_158-cu2_perl-04.png │ └── bruce_gray_wc_158-cu2_sans_rotor-02.png ├── raku_data_math-01.org ├── talks │ ├── data_math │ │ ├── Old │ │ │ ├── J-where_to_find.org │ │ │ ├── M-thanks.org │ │ │ └── L-thoughts_on_the_general_case_in_raku.org │ │ ├── L-where_to_find.org │ │ ├── A-opening_slide.txt │ │ ├── O-thanks.org │ │ ├── B-intro-hash_subtraction.pl │ │ ├── C-aside_hash_as_scalar.rectpara │ │ ├── D-hash_subtraction_fixed.pl │ │ └── F-hash_subtraction_via_Data-Math.pl │ ├── new_year_raku │ │ ├── H4-csv.raku │ │ ├── Z3-random_raku.raku │ │ ├── Z4-trial-spy_via_ampersand.pl6 │ │ ├── K8-trial-http_useragent.pl6 │ │ ├── E1-math_on_arbitrary_parallel_structures_in_perl5.org │ │ ├── C5-DataMath │ │ │ ├── B-intro-hash_subtraction.pl │ │ │ └── D-hash_subtraction_fixed.pl │ │ ├── A1-title_page.txt │ │ ├── Z2-random_perl.pl │ │ ├── Z9-other_stuff_on_raku.org │ │ ├── J2-trial-perl5_inline-solution_0.pl6 │ │ ├── H2-bruce_gray_io_lines_etc.raku │ │ └── Z8-videos_on_raku.org │ ├── file_metadata │ │ └── file_metadata.org │ └── multidispatch_vs_case │ │ └── intro.txt ├── meeting_2021jul24.org ├── raku_data_math-01.md └── meeting_2022dec04.org ├── .gitignore ├── lib ├── Data │ └── Stub.rakumod └── Doomfiles │ └── Parse.rakumod └── md_exp └── bin ├── multidispatch_overlapping_subsets_use_order_dependency-a.raku └── multidispatch_overlapping_subsets_use_order_dependency-b.raku /bin/2022mar13/tmp.lst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bin/2024dec22/dat/j/1: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bin/2024dec22/dat/j/2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /t/dat/tree1.BAK/beta.txt: -------------------------------------------------------------------------------- 1 | BCDE 2 | -------------------------------------------------------------------------------- /t/dat/tree1.BAK/alpha.txt: -------------------------------------------------------------------------------- 1 | abcd 2 | -------------------------------------------------------------------------------- /t/dat/tree1.BAK/gamma.txt: -------------------------------------------------------------------------------- 1 | CDEF 2 | -------------------------------------------------------------------------------- /t/dat/tree1.BAK/son1/aaa.txt: -------------------------------------------------------------------------------- 1 | aaa 2 | -------------------------------------------------------------------------------- /t/dat/tree1.BAK/son1/bbb.txt: -------------------------------------------------------------------------------- 1 | bbb 2 | -------------------------------------------------------------------------------- /t/dat/tree1.BAK/son1/ccc.txt: -------------------------------------------------------------------------------- 1 | ccc 2 | -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1.BAK/alpha.txt: -------------------------------------------------------------------------------- 1 | abcd 2 | -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1.BAK/beta.txt: -------------------------------------------------------------------------------- 1 | BCDE 2 | -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1.BAK/gamma.txt: -------------------------------------------------------------------------------- 1 | CDEF 2 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1.BAK/alpha.txt: -------------------------------------------------------------------------------- 1 | abcd 2 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1.BAK/beta.txt: -------------------------------------------------------------------------------- 1 | BCDE 2 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1.BAK/gamma.txt: -------------------------------------------------------------------------------- 1 | CDEF 2 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1.BAK/son1/aaa.txt: -------------------------------------------------------------------------------- 1 | aaa 2 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1.BAK/son1/bbb.txt: -------------------------------------------------------------------------------- 1 | bbb 2 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1.BAK/son1/ccc.txt: -------------------------------------------------------------------------------- 1 | ccc 2 | -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1.BAK/son1/aaa.txt: -------------------------------------------------------------------------------- 1 | aaa 2 | -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1.BAK/son1/bbb.txt: -------------------------------------------------------------------------------- 1 | bbb 2 | -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1.BAK/son1/ccc.txt: -------------------------------------------------------------------------------- 1 | ccc 2 | -------------------------------------------------------------------------------- /bin/2024dec22/dat/alpha.data: -------------------------------------------------------------------------------- 1 | A 2 | B 3 | C 4 | D 5 | E -------------------------------------------------------------------------------- /bin/2021may02/hello.raku: -------------------------------------------------------------------------------- 1 | say 'hello'; 2 | say 'goodbye'; 3 | -------------------------------------------------------------------------------- /dat/some_hebrew.txt: -------------------------------------------------------------------------------- 1 | 2 | בראשית 3 | 4 | בְּרֵאשִׁ֖ית 5 | 6 | -------------------------------------------------------------------------------- /notes/rob-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/rob-01.png -------------------------------------------------------------------------------- /notes/rob-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/rob-02.png -------------------------------------------------------------------------------- /bin/2024dec22/dat/key_test_4_bruce.dat: -------------------------------------------------------------------------------- 1 | 1 VAL21 2 | 2 VAL22 3 | 3 VAL23 4 | 4 VAL24 5 | 5 VAL25 6 | -------------------------------------------------------------------------------- /bin/2024dec22/stupid_perl_trick.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -n 2 | 3 | my $n; $n++; print $n, "\n"; 4 | -------------------------------------------------------------------------------- /notes/bg_squareful.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg_squareful.png -------------------------------------------------------------------------------- /notes/hyperrob-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/hyperrob-01.png -------------------------------------------------------------------------------- /bin/2023jul23/bg_wc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023jul23/bg_wc.png -------------------------------------------------------------------------------- /bin/2023jul23/bg_wc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023jul23/bg_wc2.png -------------------------------------------------------------------------------- /bin/2023jul23/bg_wc3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023jul23/bg_wc3.png -------------------------------------------------------------------------------- /bin/2023jul23/bg_wc4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023jul23/bg_wc4.png -------------------------------------------------------------------------------- /bin/2023sep10/marton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023sep10/marton.png -------------------------------------------------------------------------------- /bin/2024dec22/dat/split_to_sigiless.dat: -------------------------------------------------------------------------------- 1 | 1 VAL21 2 | 2 VAL22 3 | 3 VAL23 4 | 4 VAL24 5 | 5 VAL25 6 | -------------------------------------------------------------------------------- /bin/Subtitles/data/The_Judge_From_Hell-ep02.srt: -------------------------------------------------------------------------------- 1 | The_Judge_from_Hell_-_1x02_-_Episode_2.WEB.DSNP.en.srt -------------------------------------------------------------------------------- /notes/rob_code_touch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/rob_code_touch.png -------------------------------------------------------------------------------- /bin/2023sep10/marton-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023sep10/marton-01.png -------------------------------------------------------------------------------- /t/dat/tree1_original.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/t/dat/tree1_original.tar.gz -------------------------------------------------------------------------------- /bin/2023dec03/bg_stuff-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023dec03/bg_stuff-01.png -------------------------------------------------------------------------------- /bin/2023dec03/bg_stuff-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023dec03/bg_stuff-02.png -------------------------------------------------------------------------------- /notes/bg_subset_with_bags.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg_subset_with_bags.png -------------------------------------------------------------------------------- /bin/2021may02/hello-dpchrist: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | print "hello, world!\n"; 3 | print "goodbye, cruel world!\n"; 4 | -------------------------------------------------------------------------------- /bin/2023dec17/rob_num_quotes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023dec17/rob_num_quotes.png -------------------------------------------------------------------------------- /notes/bg-01-use_of_repeated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg-01-use_of_repeated.png -------------------------------------------------------------------------------- /bin/2024may05/data/issue_423.dat: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | banana 5 | 5 6 | 6 7 | 7 8 | banana 9 | 9 10 | 10 11 | 11 12 | -------------------------------------------------------------------------------- /t/Tagger/dat/tree1_original.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/t/Tagger/dat/tree1_original.tar.gz -------------------------------------------------------------------------------- /bin/2023sep10/bruce_challenge_233.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023sep10/bruce_challenge_233.png -------------------------------------------------------------------------------- /bin/2024jul28/.META: -------------------------------------------------------------------------------- 1 | Sunday July 28, 2024 5:39 PM 2 | Here, 'tis a directory of code examples which remains unused. 3 | 4 | -------------------------------------------------------------------------------- /bin/Subtitles/data/The_Judge_From_Hell-ep02.mp4: -------------------------------------------------------------------------------- 1 | ../../../../../../../../Dust/Video/TheJudgeFromHell/The_Judge_From_Hell-ep02.mp4 -------------------------------------------------------------------------------- /notes/etc/01-jj_merelo_cookbook.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/etc/01-jj_merelo_cookbook.jpg -------------------------------------------------------------------------------- /notes/etc/02-jj_merelo_cookbook.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/etc/02-jj_merelo_cookbook.jpg -------------------------------------------------------------------------------- /t/PlusMine/dat/tree1_original.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/t/PlusMine/dat/tree1_original.tar.gz -------------------------------------------------------------------------------- /bin/2022nov06/participants_diehards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2022nov06/participants_diehards.png -------------------------------------------------------------------------------- /notes/BruceGrayDataRecordRole/bg-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/BruceGrayDataRecordRole/bg-01.png -------------------------------------------------------------------------------- /notes/BruceGrayDataRecordRole/bg-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/BruceGrayDataRecordRole/bg-02.png -------------------------------------------------------------------------------- /notes/BruceGrayDataRecordRole/bg-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/BruceGrayDataRecordRole/bg-03.png -------------------------------------------------------------------------------- /notes/BruceGrayDataRecordRole/bg-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/BruceGrayDataRecordRole/bg-04.png -------------------------------------------------------------------------------- /bin/2022nov06/marton_code_odd_idioms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2022nov06/marton_code_odd_idioms.png -------------------------------------------------------------------------------- /bin/2022nov06/marton_polgar_code_ex-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2022nov06/marton_polgar_code_ex-01.png -------------------------------------------------------------------------------- /bin/2023sep10/bruce_challenge_233-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023sep10/bruce_challenge_233-01.png -------------------------------------------------------------------------------- /bin/2022nov20/robs_decontainerizng_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2022nov20/robs_decontainerizng_table.png -------------------------------------------------------------------------------- /bin/2023mar26/marton_example_rotor_on_lh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023mar26/marton_example_rotor_on_lh.png -------------------------------------------------------------------------------- /bin/leland_numbers_inventing_new_operators.pl6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/leland_numbers_inventing_new_operators.pl6 -------------------------------------------------------------------------------- /notes/bg-weekly_challenger_none_divis_by_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg-weekly_challenger_none_divis_by_2.png -------------------------------------------------------------------------------- /notes/rob_squareful_range_windowing_array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/rob_squareful_range_windowing_array.png -------------------------------------------------------------------------------- /bin/2022feb27/bruce_gray_weekly_challenge-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2022feb27/bruce_gray_weekly_challenge-01.png -------------------------------------------------------------------------------- /notes/bg_challenge_long_year_and_lychrel/bg-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg_challenge_long_year_and_lychrel/bg-01.png -------------------------------------------------------------------------------- /notes/bg_challenge_long_year_and_lychrel/bg-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg_challenge_long_year_and_lychrel/bg-02.png -------------------------------------------------------------------------------- /notes/bg_challenge_long_year_and_lychrel/bg-02a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/bg_challenge_long_year_and_lychrel/bg-02a.png -------------------------------------------------------------------------------- /bin/2023mar26/tr_and_multi_string_substitutions-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2023mar26/tr_and_multi_string_substitutions-01.png -------------------------------------------------------------------------------- /bin/2022nov06/marton_code_idioms_cartesian_set_diff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/bin/2022nov06/marton_code_idioms_cartesian_set_diff.png -------------------------------------------------------------------------------- /notes/dpchrist-perl-walk/Dpchrist-Perl-walk-flowchart.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/dpchrist-perl-walk/Dpchrist-Perl-walk-flowchart.odg -------------------------------------------------------------------------------- /notes/dpchrist-perl-walk/Dpchrist-Perl-walk-flowchart.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/dpchrist-perl-walk/Dpchrist-Perl-walk-flowchart.pdf -------------------------------------------------------------------------------- /bin/2025jun22/ord_demo.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # ord_demo.raku 22 Jun 2025 4 | 5 | use v6; 6 | 7 | say "a".ords; # (97) 8 | say "A".ords; # (65) 9 | -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2-01.png -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_cuban_primes-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_cuban_primes-01.png -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158_perl-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158_perl-01.png -------------------------------------------------------------------------------- /notes/raku_data_math-01.org: -------------------------------------------------------------------------------- 1 | * topics to research 2 | ** deepmap 3 | *** is there a "what's the path to here?" feature 4 | **** could access a second parallel structure with that path 5 | 6 | -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_farey_sequence-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_farey_sequence-01.png -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_moebius_number-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_moebius_number-01.png -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_moebius_number-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_moebius_number-02.png -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2_perl-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2_perl-03.png -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2_perl-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2_perl-04.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gitignore for Perl 6 (http://www.perl6.org) 2 | # As part of https://github.com/github/gitignore 3 | 4 | # precompiled files 5 | .precomp 6 | lib/.precomp 7 | *~ 8 | *#* 9 | BAK 10 | Old -------------------------------------------------------------------------------- /notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2_sans_rotor-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doomvox/raku-study/HEAD/notes/Week_Challenge-Moebius-Farey-etc/bruce_gray_wc_158-cu2_sans_rotor-02.png -------------------------------------------------------------------------------- /bin/.rep/2021jan24-substitution_returns_a_match.pl6-22718-HAS.bak: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # 2021jan24-substitution_returns_a_match.pl6 24 Jan 2021 4 | 5 | use v6; 6 | 7 | 8 | # alpha beta gamma 9 | 10 | -------------------------------------------------------------------------------- /bin/2023jul09/slurpy_script.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # slurpy_script.raku 09 Jul 2023 4 | 5 | use v6; 6 | 7 | sub MAIN (+@a) { 8 | for @a -> $a { 9 | say '[', "$a", ']'; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /bin/2025jul13/oddity_again.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # oddity_again.raku 13 Jul 2025 4 | 5 | use v6; 6 | 7 | ## Treating a list as a scalar turns it into it's length 8 | 9 | say (1, 2, 3)+1; 10 | # 4 11 | -------------------------------------------------------------------------------- /bin/2023sep10/command_line_options.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # command_line_options.raku 10 Sep 2023 4 | 5 | use v6; 6 | 7 | 8 | sub MAIN(Int :n(:$num)) { 9 | say "You passed: " ~ $num; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /bin/2024apr07/dat/index.csv: -------------------------------------------------------------------------------- 1 | chrom pos ref alt a1 a4 2 | 10 12345 C T aa dd 3 | 10 12345 C T aa dd 4 | 10 12345 C T aa dd 5 | 10 12345 C T aa dd 6 | 10 12345 C T aa dd 7 | 10 12345 C T aa dd 8 | -------------------------------------------------------------------------------- /bin/2024apr21/dat/index.csv: -------------------------------------------------------------------------------- 1 | chrom pos ref alt a1 a4 2 | 10 12345 C T aa dd 3 | 10 12345 C T aa dd 4 | 10 12345 C T aa dd 5 | 10 12345 C T aa dd 6 | 10 12345 C T aa dd 7 | 10 12345 C T aa dd 8 | -------------------------------------------------------------------------------- /bin/2022jul10/se.awk: -------------------------------------------------------------------------------- 1 | 2 | awk 'BEGIN { FS=" " } 3 | { c[$5]++; l[$5,c[$5]]=$0 } 4 | END { for (i in c) { 5 | if (c[i] == 3) 6 | for (j = 1 ; j <= c[i]; j++) 7 | print l[i,j] } }' $0 8 | -------------------------------------------------------------------------------- /bin/2024aug25/messing_with_ranges.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # messing_with_ranges.raku 25 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | say (1..3)[2]; # 3 9 | 10 | say (1..3).sum; # 6 11 | 12 | say (1..3).WHAT; # (Range) 13 | 14 | -------------------------------------------------------------------------------- /bin/2024sep22/array_operators.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # array_operators.raku 22 Sep 2024 4 | 5 | use v6; 6 | 7 | use CoreHackers::Sourcery; 8 | # say sourcery( @array, 'item'); 9 | 10 | say &circumfix:<[ ]>.sourcery( (1, 2, 3) ); 11 | -------------------------------------------------------------------------------- /bin/2022apr10/dat/so.dat: -------------------------------------------------------------------------------- 1 | name: 'tom' 2 | tom_age: '31' 3 | status_tom_mar: 'yes' 4 | school: 'anne' 5 | fd_year_anne: '1987' 6 | name: 'hmz' 7 | hmz_age: '21' 8 | status_hmz_mar: 'no' 9 | school: 'svp' 10 | fd_year_svp: '1982' 11 | name: 'toli' 12 | toli_age: '41' 13 | -------------------------------------------------------------------------------- /bin/2023apr16/unixstackexchange_fortran_d_to_scientific_e_and_filter_awk.sh: -------------------------------------------------------------------------------- 1 | # solution posted to unixstackexchange in awk 2 | # https://unix.stackexchange.com/a/742940/227738 3 | awk 'NF>3{gsub(/D/,"E"); for (i=1; i<=NF; i++) if ($i != $i+0) print "not a number:", $i}' file 4 | -------------------------------------------------------------------------------- /bin/.rep/substitutions-22718-BHM.rep: -------------------------------------------------------------------------------- 1 | # Enter s///g; lines, /e not allowed /g assumed. C-x # runs on other window 2 | s/beta/BETA/g; 3 | 4 | 5 | 6 | 7 | 8 | # In the modififed buffer, the prefix is C-c . 9 | # Next change: n Undo: u Accept all: A Revert all: R 10 | -------------------------------------------------------------------------------- /bin/Subtitles/data/notes-the_judge_from_hell: -------------------------------------------------------------------------------- 1 | Saturday April 26, 2025 7:29 PM 2 | 3 | This is another that seems to lag the video by a full two seconds: 4 | 5 | /home/doom/Dust/Video/TheJudgeFromHell/Subs/The_Judge_from_Hell_-_1x04_-_Episode_4.WEB.DSNP.en.srt 6 | 7 | === 8 | -------------------------------------------------------------------------------- /bin/2025oct05/missing_semi_eat_next_line.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # missing_semi_eat_next_line.raku 05 Oct 2025 4 | 5 | use v6; 6 | 7 | my $code = { uc($^thingie) }; 8 | 9 | say $code.('godzilla'); # GODZILLA 10 | 11 | # say $code 12 | # ('godzilla'); 13 | -------------------------------------------------------------------------------- /bin/2024sep22/dollar_self.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # dollar_self.raku 22 Sep 2024 4 | 5 | use v6; 6 | 7 | use CoreHackers::Sourcery; 8 | { 9 | my @array = (3, 4, 5); 10 | # say sourcery( @array, 'item'); 11 | say sourcery( @array, 'self'); 12 | } 13 | -------------------------------------------------------------------------------- /notes/talks/data_math/Old/J-where_to_find.org: -------------------------------------------------------------------------------- 1 | * where to find Data::Math 2 | ** cpan 3 | *** https://metacpan.org/pod/Data::Math 4 | *** https://metacpan.org/pod/Scalar::Classify 5 | ** github 6 | *** https://github.com/doomvox/data-math 7 | *** https://github.com/doomvox/scalar-classify 8 | 9 | -------------------------------------------------------------------------------- /bin/2024apr07/dat/data.csv: -------------------------------------------------------------------------------- 1 | chrom pos ref alt a1 a2 a3 a4 2 | 10 12345 C T aa bb cc dd 3 | 10 12345 C T aa bb cc dd 4 | 10 12345 C T aa bb cc dd 5 | 10 12345 C T aa bb cc dd 6 | 10 12345 C T aa bb cc dd 7 | 10 12345 C T aa bb cc dd 8 | -------------------------------------------------------------------------------- /bin/2024apr21/dat/data.csv: -------------------------------------------------------------------------------- 1 | chrom pos ref alt a1 a2 a3 a4 2 | 10 12345 C T aa bb cc dd 3 | 10 12345 C T aa bb cc dd 4 | 10 12345 C T aa bb cc dd 5 | 10 12345 C T aa bb cc dd 6 | 10 12345 C T aa bb cc dd 7 | 10 12345 C T aa bb cc dd 8 | -------------------------------------------------------------------------------- /bin/2024oct20/assigning_crap_to_ratoverflow.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # assigning_crap_to_ratoverflow.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | 8 | $*RAT-OVERFLOW = Str; 9 | # No such method 'UPGRADE-RAT' for invocant of type 'Str' 10 | 11 | say $*RAT-OVERFLOW; # (Str) 12 | -------------------------------------------------------------------------------- /bin/2024jun30/laziness7.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # laziness.7.raku 30 Jun 2024 4 | 5 | use v6; 6 | 7 | sub something { 8 | my @a[10001] = (1..10000); # real 0m14.353s 9 | # my @a = (1..10000); # real 0m4.014s 10 | } 11 | 12 | for 1..1000 { 13 | something(); 14 | } 15 | -------------------------------------------------------------------------------- /bin/2024oct20/fatrat_new.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # fatrat_new.raku 09 Nov 2024 4 | 5 | use v6; 6 | 7 | ## FatRat.new does create a FatRat, as expected 8 | my $nfr = FatRat.new(1, $d); 9 | say $nfr.^name, ': ', $nfr.nude; 10 | # FatRat: (1 1000000000000000000000000000000000000000000000) 11 | -------------------------------------------------------------------------------- /bin/2021dec05/bg_example_subs.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bg_example_subs.raku 05 Dec 2021 4 | 5 | use v6; 6 | 7 | # raku -e 'sub f { say 42; }; sub g {...}; say .yada for &f, &g;' 8 | # False 9 | # True 10 | 11 | sub f { 12 | say 42; 13 | }; 14 | sub g {...}; 15 | say .yada for &f, &g; 16 | -------------------------------------------------------------------------------- /bin/2024feb25/revisiting_lta_dropped_comma_on_say_array.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # revisiting_lta_dropped_comma_on_say_array.raku 25 Feb 2024 4 | 5 | use v6; 6 | 7 | 8 | my @a = < A B C >; 9 | 10 | say "output: ", @a[1]; # B 11 | 12 | 13 | say "output: " @a[1]; 14 | # Two terms in a row 15 | -------------------------------------------------------------------------------- /notes/talks/data_math/L-where_to_find.org: -------------------------------------------------------------------------------- 1 | 2 | * where to find Data::Math and Scalar::Classify 3 | ** cpan 4 | *** https://metacpan.org/pod/Data::Math 5 | *** https://metacpan.org/pod/Scalar::Classify 6 | ** github 7 | *** https://github.com/doomvox/data-math 8 | *** https://github.com/doomvox/scalar-classify 9 | 10 | -------------------------------------------------------------------------------- /bin/2023dec03/ranges_of_points_kindof.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # ranges_of_points_kindof.raku 21 Apr 2024 4 | 5 | use v6; 6 | 7 | 8 | my $s = ( (0,1) ... (3,7) ); 9 | 10 | say $s; # (0 1 2 3 7) 11 | 12 | 13 | my $r = (3+7i .. 9+13i); 14 | # Complex objects are not valid endpoints for Ranges 15 | -------------------------------------------------------------------------------- /bin/2022mar27/hendrix_numbers-02-bruce_gray.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # hendrix_numbers-02-bruce_gray.raku 27 Mar 2022 4 | 5 | use v6; 6 | 7 | say .key, " ", .value.elems 8 | for classify { !/<[69]>/ ?? "trivial" !! $_ eq .trans(<6 9> => <9 6>) ?? "hendrix" !! "none" }, 9 | 1..1000; 10 | 11 | -------------------------------------------------------------------------------- /bin/2025aug10/count_by_3.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # count_by_3.raku 24 Aug 2025 4 | 5 | use v6; 6 | 7 | for 1, 4 ... 12 { 8 | .say; 9 | } 10 | # 1 11 | # 4 12 | # 7 13 | # 10 14 | 15 | say "==="; 16 | .say for 0, 3 ... 12; 17 | # 0 18 | # 3 19 | # 6 20 | # 9 21 | # 12 22 | 23 | say 1...3,7...9; 24 | -------------------------------------------------------------------------------- /bin/2022oct23/funkiness.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # funkiness.raku 23 Oct 2022 4 | 5 | use v6; 6 | 7 | sub hm { 8 | constant $++; 9 | # Missing initializer on constant declaration 10 | } 11 | 12 | 13 | # constant 1, * * $++ .. 3; 14 | 15 | 16 | # sub hm { 17 | # use constant $++; 18 | # } 19 | 20 | -------------------------------------------------------------------------------- /bin/2025dec07/seq_vs_range_array_assign.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # seq_vs_range_array_assign.raku 07 Dec 2025 4 | 5 | use v6; 6 | 7 | ## For some purposes ranges and sequences seem equivalent 8 | { 9 | my @a = 1..3; 10 | say @a; 11 | } 12 | 13 | { 14 | my @a = 1...3; 15 | say @a; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /bin/2022jun19/dat/data_by_dates.txt: -------------------------------------------------------------------------------- 1 | 01/01/2020 2 | 24/01/2020 3 | 04/02/2020 4 | 23/02/2020 5 | 01/03/2020 6 | 13/03/2020 7 | 14/04/2020 8 | 29/05/2020 9 | 16/06/2020 10 | 17/07/2020 11 | 18/08/2020 12 | 19/09/2020 13 | 20/10/2020 14 | 21/11/2020 15 | 22/12/2020 16 | 23/01/2021 17 | 24/02/2021 18 | 01/03/2021 19 | 25/03/2021 20 | 04/04/2021 21 | -------------------------------------------------------------------------------- /bin/2023mar05/proc_simpler_call.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # proc_simpler_call.raku 26 Feb 2023 4 | 5 | use v6; 6 | 7 | 8 | my $git = run 'git', 'log', '--oneline', :out; 9 | for $git.out.lines -> $line { 10 | my ($sha, $subject) = $line.split: ' ', 2; 11 | say "$subject [$sha]"; 12 | } 13 | $git.out.close(); 14 | -------------------------------------------------------------------------------- /bin/2024aug25/ranges_positional.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # ranges_positional.raku 25 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | my $r = 1..3; 9 | say $r.WHAT; # (Range) 10 | 11 | say $r ~~ Positional; # True 12 | 13 | say $r ~~ Range; # True 14 | 15 | # Positional a role, so technically "Range does Positional" 16 | -------------------------------------------------------------------------------- /bin/2025jul13/trig_on_arrays.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # trig_on_arrays.raku 13 Jul 2025 4 | 5 | use v6; 6 | 7 | my @n = (1, 2, 3); 8 | say @n; 9 | 10 | say @n.sin; 11 | # 0.1411200080598672 12 | 13 | say 3.sin; 14 | # 0.1411200080598672 15 | 16 | ## Okay: so this misbegotten feature is still there, even with a 2025 17 | -------------------------------------------------------------------------------- /bin/2023apr30/multiline_records.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # multiline_records.raku 30 Apr 2023 4 | 5 | use v6; 6 | 7 | ## line-at-a-time 8 | my $data_file = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2023apr30/data/addresses.txt"; 9 | .say for $data_file.IO.lines.grep: { 10 | $_ 11 | } 12 | 13 | ## Supply/Tap 14 | -------------------------------------------------------------------------------- /bin/2024may19/introspection_sub_name.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # introspection_sub_name.raku 19 May 2024 4 | 5 | use v6; 6 | 7 | sub dostuff { 8 | say "Stuff it!"; 9 | } 10 | 11 | my $code = &dostuff; 12 | 13 | say $code.name; 14 | 15 | 16 | ## could simplify bruce's code runner boilerplate, instead of using pairs 17 | -------------------------------------------------------------------------------- /bin/2025sep07/silly_ex.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # silly_ex.raku 07 Sep 2025 4 | 5 | use v6; 6 | 7 | my $a = 3; 8 | my $b = 4; 9 | ## my $c = sqrt( $a**2 + $b**2 ); 10 | ## my $c = sqrt( $a² + $b² ); 11 | my $c = ( $a**2 + $b**2 )**0.5; 12 | say $c; # 5 13 | 14 | if ($c == 5) { say "yup, really five"; } 15 | # yup, really five 16 | -------------------------------------------------------------------------------- /bin/2021feb14/creating_hashes-variations_on_theme_by_lizmat.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # creating_hashes-variations_on_theme_by_lizmat.pl6 14 Feb 2021 4 | 5 | # See: 6 | # ../../raku-study/bin/2021feb14/creating_objects-variations_on_theme_by_lizmat.pl6 7 | 8 | use v6; 9 | for ^1_000_000 { 10 | my %p = x => 42, y => 666 11 | } 12 | -------------------------------------------------------------------------------- /bin/2024jul14/quoting_error.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # quoting_error.raku 14 Jul 2024 4 | 5 | use v6; 6 | 7 | # Rob question: 8 | 9 | my $x = Q{ hello there }; 10 | # If you drop the semicolon there: 11 | 12 | # Error while compiling /home/rir/q.raku 13 | # Strange text after block (missing semicolon or comma?) 14 | 15 | say $x; 16 | -------------------------------------------------------------------------------- /bin/2025sep07/pick_roll_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # pick_roll_etc.raku 07 Sep 2025 4 | 5 | use v6; 6 | 7 | say pick(1..6); 8 | # () 9 | 10 | say (1..6).pick; 11 | # 3 12 | 13 | say (1..6).roll; 14 | # 3 15 | 16 | say (1..6).pick(3); 17 | # (3 6 1) 18 | 19 | say (1..6).roll(3); 20 | # (6 5 2) 21 | 22 | 23 | # say pick(1..6); 24 | -------------------------------------------------------------------------------- /bin/2024jun30/laziness4.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # laziness4.raku 30 Jun 2024 4 | 5 | use v6; 6 | 7 | sub something { 8 | # my Int @a = (1..100000); ## script takes 1.5m 9 | # my @a = (1..100000); ## script takes 1.5m 10 | my int @a = (1..100000); ## script takes 5s 11 | } 12 | 13 | for 1..1000 { 14 | something(); 15 | } 16 | -------------------------------------------------------------------------------- /bin/2025jun08/old_smartmatch_behavior.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # old_smartmatch_behavior.raku 08 Jun 2025 4 | 5 | use v6; 6 | 7 | 8 | say 2 ~~ *.Int; # True 9 | 10 | # pop quiz, true or false? 11 | # 2 gets fed into * 12 | 13 | 14 | say 0 ~~ *.Int; # False 15 | 16 | say 0.Int; # 0 17 | 18 | 19 | ## Once upon a time, these returned 2 and 0 20 | -------------------------------------------------------------------------------- /bin/2021jun20/give_em_enough_rop.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # give_em_enough_rop.raku 20 Jun 2021 4 | 5 | use v6; 6 | 7 | # From Bruce Gray : Least favorite meta-operator: Rop 8 | # my $a = 41; 1 R+= $a; say $a; 9 | # Bwahahaha! 10 | 11 | my $a = 41; 12 | 1 R+= $a; 13 | say $a; 14 | 15 | # 42 16 | 17 | # R = reverse 18 | 19 | $a += 3.3; 20 | say $a; # 45.3 21 | -------------------------------------------------------------------------------- /bin/2022jan30/getting_hyper.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # getting_hyper.raku 16 Jan 2022 4 | 5 | use v6; 6 | 7 | ## TODO 8 | ## cool stuff with hypers 9 | ## vauge idea: intermix deepmap with hypers/reduction... 10 | ## bruce gray mentions that >>. acts like deepmap 11 | 12 | 13 | 14 | 15 | 16 | 17 | # === 18 | # Author: doom@kzsu.stanford.edu 19 | 20 | -------------------------------------------------------------------------------- /bin/2024jun30/laziness5.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # laziness5.raku 30 Jun 2024 4 | 5 | use v6; 6 | 7 | sub something { 8 | # my @a = (1..Inf); ## 0m0.747s 9 | my @a = (1..10000); ## 0m4.060s 10 | } 11 | 12 | for 1..1000 { 13 | something(); 14 | } 15 | 16 | ## Because the Inf version is necessarily lazy it's *faster* than a smaller value would be 17 | -------------------------------------------------------------------------------- /bin/2021apr25/verifying_failure_is_false.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # verifying_failure_is_false.raku 26 Apr 2021 4 | 5 | use v6; 6 | 7 | say '333'.Numeric.WHAT; # (Int) 8 | say 'thureesies'.Numeric.WHAT; # (Failure) 9 | 10 | if '33333'.Numeric { say 'true!' } else { say 'not.' } # true! 11 | if 'three'.Numeric { say 'true!' } else { say 'not.' } # not. 12 | 13 | -------------------------------------------------------------------------------- /bin/2021jun20/trailing_if.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # trailing_if.raku 20 Jun 2021 4 | 5 | use v6; 6 | 7 | say (15 if 3 > 4); # () 8 | 9 | my $var = (15 if 3 > 4); 10 | say $var.raku; # Empty 11 | say $var.WHAT; # (Slip) 12 | 13 | 14 | # my $list = | @stuff; 15 | 16 | 17 | my $huh = | 'a' | 'b' | 'c'; 18 | say $huh; # any(a, b, c) 19 | say $huh.WHAT; # (Junction) 20 | -------------------------------------------------------------------------------- /bin/2022mar27/tr.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # tr.raku 26 Mar 2022 4 | 5 | use v6; 6 | 7 | { 8 | my $n = "123456"; 9 | $n ~~ tr/36/63/; 10 | say $n; # 126453 11 | } 12 | 13 | 14 | { 15 | my $n = "123456"; 16 | if ( $n ~~ tr/36/63/ ) { 17 | say "changed to: $n"; 18 | # changed to: 126453 19 | } else { 20 | say "unchanged: $n"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /bin/2023mar05/json_comparator_bruce_gray.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # json_comparator_bruce_gray.raku 05 Mar 2023 4 | 5 | use v6; 6 | 7 | 8 | sub MAIN ( $file1, $file2 ) { 9 | my @parsings = hyper map { from-json( slurp( $_ ) ) }, $file1, $file2; 10 | say @parsings[0] eqv @parsings[1] 11 | ?? 'Files contain identical JSON' 12 | !! 'Files contain different JSON'; 13 | } 14 | -------------------------------------------------------------------------------- /bin/2024feb25/revisiting_lta_dropped_comma_on_say_hash.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # revisiting_lta_dropped_comma_on_say_hash.raku 25 Feb 2024 4 | 5 | 6 | # use :PREVIEW, v6.e; 7 | 8 | my %h = A => 1; 9 | 10 | { 11 | say "output: ", %h; 12 | } 13 | 14 | 15 | { 16 | say "output: " %h; 17 | # Undeclared routine: 18 | # h used at line 16. Did you mean 'HOW'? 19 | } 20 | -------------------------------------------------------------------------------- /bin/2022jan16/alternate_approach_ch2.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # alternate_approach_ch2.raku 16 Jan 2022 4 | 5 | use v6; 6 | 7 | constant @pents = map -> \n { n *( 3*n - 1 ) div 2 }, 1..*; 8 | 9 | my %p = @pents.head(2400).Set; 10 | 11 | %p{ [+] .list ] 12 | say @pents.head(2400).combinations(2).first( 13 | { %p{ [+] .list } 14 | and %p{ [R-] .list } } 15 | ); 16 | 17 | -------------------------------------------------------------------------------- /bin/2024feb25/fussy_uint.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # fussy_uint.raku 25 Feb 2024 4 | 5 | use v6; 6 | 7 | ## ToddAndMargo was surprised this doesn't error out 8 | ## my uint16 $x = -1; 9 | 10 | ## I thought you could do this, but: 11 | 12 | subset FussyUint16 of uint16 where 0 >= * < 2 ** 16; 13 | 14 | ## ===SORRY!=== Error while compiling ... 15 | ## Subsets of native types not yet implemented. Sorry. 16 | -------------------------------------------------------------------------------- /bin/2023mar26/assigning_nil.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # assigning_nil.raku 26 Mar 2023 4 | 5 | use v6; 6 | 7 | 8 | { 9 | my @array = 1, 2, Nil, 4; 10 | say @array; ## [1 2 (Any) 4] 11 | 12 | my Int @ints = 1, 2, Nil, 4; 13 | say @ints; ## [1 2 (Int) 4] 14 | 15 | 16 | class Idiot is Any { }; 17 | 18 | my Idiot @idiots = 1, 2, Nil, 4; 19 | say @idiots; 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bin/2021jun20/ternaryism.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # ternaryism.raku 20 Jun 2021 4 | 5 | use v6; 6 | 7 | my $condition = True; 8 | 9 | my $result = $condition ?? "first" !! "second"; 10 | say "result: $result\n"; # result: first 11 | 12 | my $result2 = do 13 | if $condition { 14 | "first"; 15 | } else { 16 | "second"; 17 | }; 18 | say "result2: $result2\n"; # result2: first 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /bin/2025apr13/old_q_regexp_objects_built_from_list.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # old_q_regexp_objects_built_from_list.raku 13 Apr 2025 4 | 5 | use v6; 6 | 7 | 8 | my @numbers = < wuhn tew thuree foah fahv sex sevhun >; 9 | 10 | my $stringy = "You know wuhn of these days I'll figure that out."; 11 | 12 | say $stringy ~~ /@numbers/; # 「wuhn」 13 | 14 | ## Very simple to turn a list into an or regexp, just use it. 15 | -------------------------------------------------------------------------------- /bin/2021apr25/bg_stuff.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bg_stuff.raku 25 Apr 2021 4 | 5 | use v6; 6 | 7 | my @a = , , ; 8 | for @a -> [$first, $second] { ## some languages call this "pattern matching"? A pattern in the signature. 9 | 10 | say "first: $first"; 11 | say "second: $second"; 12 | 13 | } 14 | 15 | # first: A 16 | # second: B 17 | # first: D 18 | # second: E 19 | # first: X 20 | # second: Y 21 | -------------------------------------------------------------------------------- /bin/2024dec22/running_raku_method_on_raku_output.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # running_raku_method_on_raku_output.raku 22 Dec 2024 4 | 5 | use v6; 6 | 7 | my $a; 8 | say $a; # (Any) 9 | 10 | my $b = $a.raku; 11 | say $b; # Any 12 | 13 | my $c = $b.raku; 14 | say $c; # "Any" 15 | 16 | my $d = $c.raku; 17 | say $d; # "\"Any\"" 18 | 19 | my $e = $d.raku; 20 | say $e; # "\"\\\"Any\\\"\"" 21 | 22 | -------------------------------------------------------------------------------- /notes/talks/data_math/A-opening_slide.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | June 9, 2021 4 | 5 | 6 | Working on Roughly Parallel Data Structures, 7 | e.g. with Data::Math 8 | 9 | Joseph Brenner 10 | http://obsidianrook.com/doomfiles 11 | 12 | 13 | I run the SF Perl "Raku Study Group" (next one on June 20th) 14 | https://www.meetup.com/San-Francisco-Perl/ 15 | 16 | (But this is mostly a Perl talk.) 17 | -------------------------------------------------------------------------------- /bin/2022oct23/modgrid/jb_modgrid_01.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # jb_modgrid_01.raku 08 Oct 2022 4 | 5 | use v6; 6 | 7 | my $dat_loc = $*PROGRAM.parent.add('dat'); 8 | chdir( $dat_loc ); 9 | 10 | # my $file = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022oct23/modgrid/dat/warrior_weaponry.txt"; 11 | my $file = "warrior_weaponry.txt"; 12 | for $file.IO.lines -> $line { 13 | say $line.flip.split(/\s+/, 5).join("\t").flip; 14 | } 15 | -------------------------------------------------------------------------------- /bin/2025aug10/hm.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # hm.raku 24 Aug 2025 4 | 5 | use v6; 6 | 7 | my @a = (1,2,3,4,5,6,7,8,9,10,11,12,13); 8 | 9 | say @a[0..3,5..7]; # ((1 2 3 4) (6 7 8)) 10 | 11 | say @a[ | 0..3, | 5..7]; # ((2 3 4) (2 3 4 5 6 7 8)) 12 | 13 | 14 | say @a[ flat 0..3, 5..7]; # (1 2 3 4 6 7 8) 15 | say @a[ flat( 0..3, 5..7)]; # (1 2 3 4 6 7 8) 16 | 17 | say "==="; 18 | 19 | say @a[ [|] 0..3, 5..7]; # any((1 2 3 4), (6 7 8)) 20 | -------------------------------------------------------------------------------- /notes/meeting_2021jul24.org: -------------------------------------------------------------------------------- 1 | * meeting notes July 24, 2021 2 | ** special staturday session 3 | *** which we're commemorating with a complete lack of preparation 4 | ** bill's discussion on an upcoming lightning talk 5 | *** intro to raku regexes, working with negro baseball league data 6 | https://nlbm.mlblogs.com/negro-leagues-players-played-major-role-in-world-war-ii-4bc5cb125b7f 7 | 8 | *** my favorite BASIC program 9 | 10 PRINT CHR(RND(73)+23); GOTO 10 10 | 11 | -------------------------------------------------------------------------------- /notes/raku_data_math-01.md: -------------------------------------------------------------------------------- 1 | - [topics to research](#orgc461252) 2 | - [deepmap](#org8977aff) 3 | - [is there a "what's the path to here?" feature](#org2e931ba) 4 | 5 | 6 | 7 | 8 | # topics to research 9 | 10 | 11 | 12 | 13 | ## deepmap 14 | 15 | 16 | 17 | 18 | ### is there a "what's the path to here?" feature 19 | 20 | 1. could access a second parallel structure with that path 21 | -------------------------------------------------------------------------------- /bin/2021sep26/csv.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # csv.raku 26 Sep 2021 4 | 5 | use v6; 6 | 7 | # William Michals one-liner 8 | # raku -MText::CSV -e 'my $csv=Text::CSV.new; .perl.put for $csv.getline_all(open($*ARGFILES, :r, :!chomp));' 9 | 10 | use Text::CSV; 11 | 12 | my $csv=Text::CSV.new; 13 | for $csv.getline_all( open( $*ARGFILES, :r, :!chomp ) ) { 14 | .perl.put 15 | } 16 | 17 | 18 | # === 19 | # Author: doom@kzsu.stanford.edu 20 | 21 | -------------------------------------------------------------------------------- /bin/2023sep24/dat/issue_34_truncated.csv: -------------------------------------------------------------------------------- 1 | 1664;4;5;35;37;43 2 | 1663;21;23;32;40;49 3 | 1662;16;17;34;35;44 4 | 1661;2;9;23;32;40;6;7 5 | 1660;23;25;30;44;47;9;12 6 | 1659;3;5;9;32;43;6;10 7 | 1658;4;6;10;13;34 8 | 1657;8;9;33;35;40 9 | 1656;15;20;31;44;48 10 | 1655;25;27;35;40;45 11 | 1654;7;32;33;34;38;6;9 12 | 1653;5;7;11;27;37;6;12 13 | 1652;7;31;33;35;36;7;10 14 | 1651;4;12;34;35;45;1;9 15 | 1650;5;8;29;35;48;5;6 16 | 1649;2;11;28;42;48;4;9 17 | 1648;2;11;12;19;38;4;8 18 | -------------------------------------------------------------------------------- /bin/2021aug15/trial-spy_via_ampersand.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # trial-spy_via_ampersand.pl6 20 Sep 2020 4 | 5 | use v6; 6 | 7 | my @monsters = 8 | << godzilla blob mothera mechazilla tingler garuda gammera >>; 9 | 10 | # dd @monsters; 11 | 12 | say "result: ", @monsters.grep({ m/^g/ }).&spy.grep({ m/z/ }).map({ .uc }); 13 | 14 | sub spy { 15 | say "Spying on: ", callframe(1); 16 | dd @_; 17 | return @_; 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /bin/2022jun19/raku: -------------------------------------------------------------------------------- 1 | 1 01/01/2020$ 2 | 2 24/01/2020$ 3 | 3 04/02/2020$ 4 | 4 23/02/2020$ 5 | 5 01/03/2020$ 6 | 6 13/03/2020$ 7 | 7 14/04/2020$ 8 | 8 29/05/2020$ 9 | 9 16/06/2020$ 10 | 10 17/07/2020$ 11 | 11 18/08/2020$ 12 | 12 19/09/2020$ 13 | 13 20/10/2020$ 14 | 14 21/11/2020$ 15 | 15 22/12/2020$ 16 | 16 23/01/2021$ 17 | 17 24/02/2021$ 18 | 18 01/03/2021$ 19 | 19 25/03/2021$ 20 | 20 04/04/2021$ 21 | -------------------------------------------------------------------------------- /bin/2024oct20/assigning_crap_to_ratoverflow-i.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # assigning_crap_to_ratoverflow.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | { 8 | my $*RAT-OVERFLOW = Str; 9 | # No such method 'UPGRADE-RAT' for invocant of type 'Str' 10 | 11 | say $*RAT-OVERFLOW; # (Str) 12 | } 13 | 14 | { 15 | temp $*RAT-OVERFLOW = Str; 16 | # No such method 'UPGRADE-RAT' for invocant of type 'Str' 17 | 18 | say $*RAT-OVERFLOW; # (Str) 19 | } 20 | -------------------------------------------------------------------------------- /bin/2021oct24/try_and_fallback.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # try_and_fallback.raku 24 Oct 2021 4 | 5 | use v6; 6 | 7 | sub toho_alone( $input = prompt ) { 8 | if ( $input eq 'gammera' ) { 9 | die "wrong production company"; 10 | } 11 | return $input; 12 | } 13 | 14 | my $default = 'godzilla'; 15 | 16 | my $ret = ((try toho_alone()) // $default); 17 | say $ret; 18 | 19 | 20 | 21 | 22 | 23 | 24 | # === 25 | # Author: doom@kzsu.stanford.edu 26 | 27 | -------------------------------------------------------------------------------- /bin/2023sep24/dat/issue_34.csv: -------------------------------------------------------------------------------- 1 | 1664;4;5;35;37;43;5;6 2 | 1663;21;23;32;40;49;8;11 3 | 1662;16;17;34;35;44;5;10 4 | 1661;2;9;23;32;40;6;7 5 | 1660;23;25;30;44;47;9;12 6 | 1659;3;5;9;32;43;6;10 7 | 1658;4;6;10;13;34;3;5 8 | 1657;8;9;33;35;40;3;6 9 | 1656;15;20;31;44;48;1;3 10 | 1655;25;27;35;40;45;7;11 11 | 1654;7;32;33;34;38;6;9 12 | 1653;5;7;11;27;37;6;12 13 | 1652;7;31;33;35;36;7;10 14 | 1651;4;12;34;35;45;1;9 15 | 1650;5;8;29;35;48;5;6 16 | 1649;2;11;28;42;48;4;9 17 | 1648;2;11;12;19;38;4;8 18 | -------------------------------------------------------------------------------- /bin/2023sep24/dat/issue_34_raw.csv: -------------------------------------------------------------------------------- 1 | 1664;4;5;35;37;43;5;6 2 | 1663;21;23;32;40;49;8;11 3 | 1662;16;17;34;35;44;5;10 4 | 1661;2;9;23;32;40;6;7 5 | 1660;23;25;30;44;47;9;12 6 | 1659;3;5;9;32;43;6;10 7 | 1658;4;6;10;13;34;3;5 8 | 1657;8;9;33;35;40;3;6 9 | 1656;15;20;31;44;48;1;3 10 | 1655;25;27;35;40;45;7;11 11 | 1654;7;32;33;34;38;6;9 12 | 1653;5;7;11;27;37;6;12 13 | 1652;7;31;33;35;36;7;10 14 | 1651;4;12;34;35;45;1;9 15 | 1650;5;8;29;35;48;5;6 16 | 1649;2;11;28;42;48;4;9 17 | 1648;2;11;12;19;38;4;8 18 | -------------------------------------------------------------------------------- /bin/2023sep24/dat/issue_34_bills_truncs.csv: -------------------------------------------------------------------------------- 1 | 1664;4;5;35;37;43;5;6 2 | 1663;21;23;32;40;49;8;11 3 | 1662;16;17;34;35;44;5;10 4 | 1661;2;9;23;32;40;6 5 | 1660;23;25;30;44;47;9;12 6 | 1659;3;5;9;32;43;6;10 7 | 1658;4;6;10;13;34;3;5 8 | 1657;8;9;33;35;40;3;6 9 | 1656;15;20;31;44;48;1;3 10 | 1655;25;27;35;40;45;7;11 11 | 1654;7;32;33;34;38;6;9 12 | 1653;5;7;11;27;37;6;12 13 | 1652;7;31;33;35;36;7;10 14 | 1651;4;12;34;35;45;1;9 15 | 1650;5;8;29;35;48;5;6 16 | 1649;2;11;28;42;48;4;9 17 | 1648;2;11;12;19;38;4;8 18 | -------------------------------------------------------------------------------- /bin/2025aug10/ranges_and_sequences_oh_my.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # ranges_and_sequences_oh_my.raku 10 Aug 2025 4 | 5 | use v6; 6 | 7 | say 0...5,3...7; 8 | # (0 1 2 3 4 7) 9 | 10 | say 0...5; 11 | # (0 1 2 3 4 5) 12 | 13 | 14 | say 0..5,3..7; 15 | # 0..53..7 16 | put 0..5,3..7; 17 | # 0 1 2 3 4 53 4 5 6 7 18 | 19 | put (0..5,3..7).raku; ## (0..5, 3..7) 20 | 21 | say 0..5; # 0..5 22 | say 3..7; # 3..7 23 | 24 | 25 | say (0..5,3..7).flat; # (0 1 2 3 4 5 3 4 5 6 7) 26 | 27 | -------------------------------------------------------------------------------- /bin/2025nov02/dat/simple.org: -------------------------------------------------------------------------------- 1 | * grammars 2 | ** TODO needs more 3 | ** docs 4 | *** Grammar Tutorial: https://docs.raku.org/language/grammar_tutorial 5 | **** "GT" 6 | *** Grammar Reference: https://docs.raku.org/language/grammars 7 | **** "GR" 8 | ** "Grammars parse strings and return data structures ..." -- GT 9 | *** a string transformed into a structure 10 | **** note: can be lossy 11 | **** structure means "hierarchies and lists", right? 12 | ***** TODO how about graphs (in general, not just DAGs) 13 | -------------------------------------------------------------------------------- /dat/doomfiles/README: -------------------------------------------------------------------------------- 1 | raku-study/dat/doomfiles 2 | 3 | Contains some html files from 4 | 5 | http://obsidianrook.com/doomfiles 6 | 7 | And these are Copyright Joseph Brenner, I guess-- but permission 8 | is granted to distribute copies of these files with the raku-study code: 9 | 10 | Scripts such as these use these as raw material to try to parse: 11 | 12 | raku-study/bin/2021mar28/doomfiles_browse_sequence-ii.raku 13 | raku-study/bin/2021mar28/doomfiles_browse_sequence-iii.raku 14 | 15 | 16 | -------------------------------------------------------------------------------- /bin/DataCook/data_joins.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # data_joins.raku 18 Sep 2024 4 | 5 | use v6; 6 | 7 | ## Looking at joining data in raku, ala RDMS table joins 8 | 9 | # my @monsters = < godzilla grendel wormface blob >; 10 | # my @monsters = < ankou araxxor borrokar damis delrith elvarg kalrag yuri >; ## www.runehq.com 11 | # my @monsters = < godzilla mothera ghidora gammera golem rhodan >; 12 | # my @monsters = < basilisk minotaur behemoth leviathan ziz chimera manticore >; 13 | 14 | -------------------------------------------------------------------------------- /bin/Subtitles/data/short.srt: -------------------------------------------------------------------------------- 1 | 1 2 | 00:00:28,862 --> 00:00:33,951 3 | The Judge from Hell 4 | 5 | 2 6 | 00:00:34,034 --> 00:00:35,970 7 | CHARACTERS, PLACES, ORGANIZATIONS, 8 | AND EVENTS IN THIS DRAMA ARE FICTITIOUS 9 | 10 | 3 11 | 00:00:35,994 --> 00:00:38,956 12 | CHILD ACTORS AND ANIMALS 13 | FILMED IN SAFE SITUATIONS 14 | 15 | 4 16 | 00:00:39,039 --> 00:00:41,017 17 | Defendant, 18 | your final statement, please. 19 | 20 | 5 21 | 00:00:41,041 --> 00:00:42,584 22 | I know I won't see her again, 23 | 24 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/H4-csv.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # csv.raku 26 Sep 2021 4 | 5 | # William Michals one-liner 6 | # raku -MText::CSV -e 'my $csv=Text::CSV.new; .perl.put for $csv.getline_all(open($*ARGFILES, :r, :!chomp));' 7 | 8 | use Text::CSV; 9 | 10 | sub MAIN () { 11 | my $csv=Text::CSV.new; 12 | for $csv.getline_all( open( $*ARGFILES, :r, :!chomp ) ) { 13 | .perl.put; 14 | } 15 | } 16 | 17 | 18 | 19 | # === 20 | # Author: doom@kzsu.stanford.edu 21 | 22 | -------------------------------------------------------------------------------- /bin/2021sep26/is_it_an_list_maybe.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # is_it_an_list_maybe.raku 25 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | my $a = 'aaa>'; 9 | 10 | 11 | say $a.elems; # 1 12 | say $a.chars; # 3 13 | 14 | say $a.WHAT; # (Str) 15 | 16 | say "==="; 17 | $a.^methods>>.say; 18 | say "==="; 19 | 20 | my @monsters = < basilisk minotaur behemoth leviathan ziz chimera manticore >; 21 | 22 | @monsters.^methods>>.say; 23 | 24 | say "==="; 25 | 26 | say @monsters.sin; # 0.6569865987187891 27 | -------------------------------------------------------------------------------- /bin/2024dec22/split_to_sigiless.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | 3 | 4 | # 5 | # split_to_sigiless.raku 22 Dec 2024 6 | 7 | use v6; 8 | 9 | chdir( "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024dec22/" ); 10 | my $dat_file = "dat/split_to_sigiless.dat" 11 | 12 | 13 | for $dat_file.IO.lines -> $line { 14 | # Do something with $line 15 | my (\k, \d, \f, \e) = $line.split("|"); 16 | 17 | say k; 18 | 19 | # say join "|", k, d, $_, e for f.split(","); 20 | } 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /bin/2025aug24/bg.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # bg.raku 24 Aug 2025 4 | 5 | use v6; 6 | 7 | ## Bruce Gray code example 8 | 9 | sub MAIN ( *@wanted ) { 10 | my @nums = ^Inf; 11 | 12 | my @w = @wanted.map: { /^(\d+)\-(\d+)$/ ?? |(+$0..+$1) !! $_ }; 13 | 14 | # Allow reverse ranges: 15 | # my @w = @wanted.map: { /^(\d+)\-(\d+)$/ ?? |( $0 <= $1 ?? +$0..+$1 !! reverse(+$1..$0)) !! $_ }; 16 | 17 | say @nums[flat @w]; 18 | } 19 | 20 | # Run like: raku x12.raku 3-5 7 9 10-12 15-13 21 | -------------------------------------------------------------------------------- /bin/2023dec31/rotor.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # rotor.raku 31 Dec 2023 4 | 5 | use v6; 6 | 7 | say ('a' .. 'f').rotor(2); 8 | # ((a b) (c d) (e f)) 9 | 10 | say ('a' .. 'g').rotor(2); 11 | # ((a b) (c d) (e f)) 12 | 13 | 14 | say ('a' .. 'g').batch(2); 15 | # ((a b) (c d) (e f) (g)) 16 | 17 | say ('a' .. 'g').rotor(2, :partial); 18 | # ((a b) (c d) (e f) (g)) 19 | 20 | 21 | 22 | ### say "gojira".split('').rotor(3); 23 | ### # (( g o) (j i r)) # W: where did the leading space come from? 24 | 25 | 26 | -------------------------------------------------------------------------------- /bin/2023apr30/data/nutrients_merelo.csv: -------------------------------------------------------------------------------- 1 | "33333333","003","Blather","LCCS","30.59","g" 2 | "00000000","003","Blather","LCCS","37.42","g" 3 | "83838383","003","Blather","LCCS","32.73","g" 4 | "45332602","203","Protein","LCCS","70.59","g" 5 | "45333759","203","Protein","LCCS","77.42","g" 6 | "45333760","203","Protein","LCCS","72.73","g" 7 | "23232323","006","Blather","LCCS","60.59","g" 8 | "00000000","006","Blather","LCCS","97.42","g" 9 | "66666666","006","Protein","LCCS","97.42","g" 10 | "86868686","006","Blather","LCCS","62.73","g" 11 | -------------------------------------------------------------------------------- /bin/2022dec18/bool_value_of_zero.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bool_value_of_zero.raku 18 Dec 2022 4 | 5 | use v6; 6 | 7 | my $i = 0; 8 | my $s = '0'; 9 | 10 | say $i.Bool; # False 11 | say $s.Bool; # True 12 | 13 | # while 1 { 14 | # my $any = prompt('gimme a 0:'); 15 | # say $any.chars; 16 | # say so $any; 17 | # } 18 | 19 | 20 | ## bruce gray 21 | # raku -e 'say map *.so, <5>, <0>, 0;' 22 | # (True False False) 23 | 24 | say map *.so, <5>, <0>, 0; # (True False False) 25 | 26 | say so '0'; # True 27 | -------------------------------------------------------------------------------- /bin/DeepMap/zip_redux.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # zip_redux.raku 04 Feb 2025 4 | 5 | use v6; 6 | 7 | { # 8 | my %new; 9 | %new = %threat.keys [Z] %threat.values; 10 | say %new; 11 | # {dracula 4 => (rhodan 5), horta IterationEnd => (godzilla 8), mothera 6 => (blob 3), wolfman 3 => (tingler 3)} 12 | } 13 | 14 | { 15 | my @a = ; 16 | my @n = 1, 2, 3; 17 | 18 | my $result = @a [Z] @n; 19 | say $result; # [a b c] 20 | 21 | ## I still understand zip naught. 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bin/MultiDispatch/older_the_i_rule-doesnt_rule.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # the_i_rule-doesnt_rule.raku 12 Aug 2024 4 | 5 | use v6; 6 | 7 | multi sub speak (Str $s) { 8 | say "1: Str, $s"; 9 | } 10 | 11 | multi sub speak (IntStr $s) { 12 | say "2: IntStr, $s"; 13 | } 14 | 15 | 16 | speak("3"); # 1: Str, 3 17 | 18 | speak(7); # Cannot resolve caller speak(Int:D); none of these signatures matches: 19 | # (Str $s) 20 | # (IntStr $s) 21 | 22 | 23 | ## TODO Need to rethink... 24 | -------------------------------------------------------------------------------- /bin/2022oct09/trailing_bracket_sans_semicolon.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # trial_trailing_bracket_sans_semic.raku 09 Oct 2022 4 | 5 | use v6; 6 | 7 | if 1 { 8 | say "fine"; # fine 9 | } 10 | ## no need for semi-c after a closing code block brace 11 | 12 | ## if the brace isn't a code block, you need the semi-c 13 | warn qq{"hey"}; 14 | 15 | say "==="; 16 | 17 | # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022oct09/trial_trailing_bracket_sans_semic.raku line 13 18 | 19 | # === 20 | 21 | -------------------------------------------------------------------------------- /bin/2023apr16/unixstackexchange_fortran_d_to_scientific_e_and_filter-bg.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # 16 Apr 2023 4 | 5 | use v6; 6 | 7 | ## bruce gray solution: 8 | # raku -ne ' 9 | # .say and next if .contains: "DEG ="; 10 | # next if /«\d\.\d\d\d\-\d\d\d»/; 11 | # say " ", .words[0,4]».subst("D","E").join(" "); 12 | # ' so_1.dat 13 | 14 | for lines() { 15 | .say and next if .contains: "DEG ="; 16 | next if /«\d\.\d\d\d\-\d\d\d»/; 17 | say " ", .words[0,4]».subst("D","E").join(" "); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /bin/2024jul14/quoting_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # quoting_etc.raku 14 Jul 2024 4 | 5 | use v6; 6 | 7 | 8 | 'thing' => $thing 9 | 10 | $hash{thing} = $thing; 11 | 12 | %hash{'thing'} = $thing; 13 | %hash = $thing; 14 | 15 | my $word = ; 16 | my @words = ; 17 | my $one_string = 'one thing after another'; 18 | 19 | my @words = q:w"one thing after another"; 20 | 21 | my @words = <>; 22 | 23 | my @words = «one thing after another $thing»; 24 | 25 | -------------------------------------------------------------------------------- /bin/2025jul13/duckmap_sigs.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # duckmap_sigs.raku 15 Jul 2025 4 | 5 | use v6; 6 | 7 | { 8 | .duckmap(-> $_ where Numeric { $_ + 1 }).say; 9 | # (a b c 2 3 4) 10 | } 11 | 12 | { 13 | # This works, but I'm not sure why: 14 | .duckmap( *.Numeric + 1 ).say; 15 | # (a b c 2 3 4) 16 | } 17 | 18 | { 19 | # say "a".Int; 20 | ## Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏a' (indicated by ⏏) 21 | } 22 | -------------------------------------------------------------------------------- /bin/2024jul14/multidispatch-01.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # multidispatch-01.raku 14 Jul 2024 4 | 5 | use v6; 6 | 7 | multi sub action( Str $thing ) { 8 | say "ONE: $thing!"; 9 | } 10 | 11 | 12 | multi sub action( $thing ) { 13 | say "TWO: $thing"; 14 | } 15 | 16 | multi sub action( :$thing ) { ## named argument via the idiomatic raku short-hand for the pair: 'thing' => $thing 17 | say "THREE: $thing"; 18 | } 19 | 20 | action( "hey" ); 21 | # ONE: hey! 22 | 23 | action( thing => "ho" ); 24 | # THREE: ho 25 | -------------------------------------------------------------------------------- /bin/2023apr30/data/addresses.txt: -------------------------------------------------------------------------------- 1 | # List of addresses, in an ad hoc text format 2 | 3 | Joseph Brenner 4 | 1003 Stanford Ave 5 | Oakland, CA 94608 6 | 7 | The Imogene Corporation 8 | New York, NY 10018 9 | 10 | National Center for Chronic Disease Prevention and Health Promotion 11 | Centers for Disease Control and Prevention 12 | Mailstop F-80 13 | 4770 Buford Highway, NE 14 | Atlanta, GA, 30341-3717 15 | 16 | Red Zillo 17 | 1454 Taylor St, APT 2, 18 | San Francisco, CA 94133 19 | 20 | Ada Trapped 21 | 621 Escondido Rd, 22 | Stanford, CA 94305 23 | 24 | -------------------------------------------------------------------------------- /bin/2024may19/powers_of_two: -------------------------------------------------------------------------------- 1 | #!/opt/rakudo-star-2018.01/bin/perl6 2 | # 3 | # Sat April 07, 2018 15:23 tango 4 | # ~/End/Cave/Perl6/bin/powers_of_two 5 | 6 | say "hello"; 7 | 8 | # loop ( my $i = 1; $i <= 256; $i++ ) { 9 | my $width = 60; 10 | my $fmt = "%4d: %" ~ $width ~ "d\n"; 11 | say "fmt: $fmt"; 12 | # for (1 .. 1024) -> $i { 13 | for (1024 .. 2024) -> $i { 14 | my $val = 2 ** $i; 15 | printf $fmt, $i, $val; 16 | } 17 | 18 | # 64: 18446744073709551616 19 | 20 | # 18,446,744,073,709,551,616 21 | -------------------------------------------------------------------------------- /bin/2025aug10/infinite_sequence.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # infinite_sequence.raku 24 Aug 2025 4 | 5 | use v6; 6 | 7 | 8 | my $s = (1 ... (Inf)); 9 | 10 | say $s; ## (...) 11 | put $s; ## ... 12 | 13 | # for 1 ... (Inf) { 14 | # say "uh oh...: $_"; 15 | # } 16 | 17 | say "==="; 18 | .say for 1 .. 3; # 1 2 3 19 | 20 | say "==="; 21 | .say for 9 .. 7; ## nada 22 | 23 | say "==="; 24 | .say for 9 ... 7; ## 9 8 7 25 | ## 26 | 27 | say "==="; 28 | .say for 'a' ... 'z'; 29 | say "==="; 30 | .say for 'A' ... 'z'; 31 | -------------------------------------------------------------------------------- /bin/2025aug10/seq_exhaustion_change.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # seq_exhaustion_change.raku 10 Aug 2025 4 | 5 | use v6; 6 | 7 | ## brian d foy example, p. 101 "Learning Perl 6": 8 | 9 | { 10 | my $s := 1 ... 5; 11 | put $s.reverse; 12 | put $s; 13 | 14 | ## That second put now errors out, with helpful error message: 15 | 16 | # The iterator of this Seq is already in use/consumed by another Seq (you 17 | # might solve this by adding .cache on usages of the Seq, or by assigning 18 | # the Seq into an array) 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bin/MultiDispatch/the_i_rule-doesnt_rule.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # the_i_rule-doesnt_rule.raku 12 Aug 2024 4 | 5 | use v6; 6 | 7 | multi sub speak (Str $s) { 8 | say "1: Str, $s"; 9 | } 10 | 11 | multi sub speak (Str $s) { 12 | say "2: ANOTHER Str, $s"; 13 | } 14 | 15 | speak("yes?"); 16 | 17 | # Ambiguous call to 'speak(Str)'; these signatures all match: 18 | # (Str $s) 19 | # (Str $s) 20 | # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/MultiDispatch/the_i_rule-doesnt_rule.raku line 15 21 | -------------------------------------------------------------------------------- /bin/2023apr16/unixstackexchange_fortran_d_to_scientific_e_and_filter-ii.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # 16 Apr 2023 4 | 5 | ## another william michaels solution 6 | 7 | use v6; 8 | 9 | my @a; 10 | for lines.join("\n").split(/ \n /) { 11 | @a.push: %(.split("\n").[0].words.[2] => .split("\n")[1..*].map(*.words[0,4])>>.map(*.subst( / (\d+) (<[+-]>) /, {$0 ~ "e" ~ $1} ).subst(/D/, "e") )>>.Num) 12 | }; 13 | for @a { for ($_.kv) -> $k,$v {put ([Z] $k xx $v.elems, $v>>.map( -> $i { ($i =~= 0) ?? 0 !! $i } )).join: "\n"}}; 14 | 15 | -------------------------------------------------------------------------------- /bin/2023mar05/bg_inline_perl5_code_ref.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # bg_inline_perl5_code_ref.raku 26 Feb 2023 4 | 5 | use v6; 6 | 7 | ## Bruce grey says this Just Works, 8 | 9 | use Inline::Perl5; 10 | my $p5 = Inline::Perl5.new; 11 | my $code_ref = $p5.run: q:to/END/; 12 | sub p5_data { 13 | my @monsters = qw( godzilla blob tingler kong dorisday ); 14 | return @monsters; 15 | } 16 | \&p5_data; 17 | END 18 | say $code_ref.(); # Expect to see: godzilla blob tingler kong dorisday 19 | # returns the *list* 20 | -------------------------------------------------------------------------------- /bin/2024jun30/laziness6.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # laziness.6.raku 30 Jun 2024 4 | 5 | use v6; 6 | 7 | sub something { 8 | # my $a := (1..10000); # script time 0m0.823s 9 | # my $a = (1..10000); # script time 0m0.921s 10 | # my @a = (1..10000); # script time 0m3.567s 11 | my @a := (1..10000); # script time real 0m0.811s 12 | say @a.WHAT; # (Range) 13 | say @a[99]; # 100 14 | 15 | # @a[99] = 666; # Cannot modify an immutable Range (1..10000) 16 | } 17 | 18 | for 1..1000 { 19 | something(); 20 | } 21 | -------------------------------------------------------------------------------- /bin/MultiDispatch/.META: -------------------------------------------------------------------------------- 1 | Tuesday July 30, 2024 11:34 PM 2 | /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/MultiDispatch 3 | 4 | Multidispatch experiments, placed in an undated directory 5 | because I expect this go on for some time. 6 | 7 | Might work up a more complex project, e.g. to use in a talk, 8 | or as a development ground for new rakudo tests. 9 | 10 | 11 | There's a bunch of older examples here that can be played with: 12 | 13 | /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2021sep26/multi_dispatch_with_overlapping_subset_types.raku 14 | 15 | -------------------------------------------------------------------------------- /bin/2022feb27/isolated_file_list_assigned_to_scalar.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # isolated_file_list_assigned_to_scalar.raku 27 Feb 2022 4 | 5 | use v6; 6 | 7 | { 8 | my $data = 1, 2, 3; 9 | say $data.raku; # 1 10 | say $data.WHAT; # (Int) 11 | } 12 | 13 | # WARNINGS for /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022feb27/isolated_file_list_assigned_to_scalar.raku: 14 | # Useless use of constant integer 3 in sink context (lines 8, 8) 15 | # Useless use of constant integer 2 in sink context (lines 8, 8) 16 | # 1 17 | # (Int) 18 | -------------------------------------------------------------------------------- /bin/2022jul10/anonymous_hash_intermediary.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # anonymous_hash_intermediary.raku 10 Jul 2022 4 | 5 | use v6; 6 | 7 | { 8 | say my %h = % = %(:a(1)); 9 | # {a => 1} 10 | } 11 | 12 | { 13 | say my %h =%= %(:a(1)); 14 | # {a => 1} 15 | } 16 | 17 | 18 | { 19 | say my %h = %(:a(1)); 20 | # {a => 1} 21 | } 22 | 23 | 24 | sub say_num ( $str ) { 25 | say $++, ": $str"; 26 | } 27 | 28 | 29 | say_num("hey"); 30 | say_num("there"); 31 | say_num("you guys"); 32 | # 0: hey 33 | # 1: there 34 | # 2: you guys 35 | 36 | -------------------------------------------------------------------------------- /bin/reduction_metaoperators.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # reduction_metaoperators.pl6 11 Oct 2020 4 | 5 | 6 | use v6; 7 | 8 | my @a = (1, 2, 3, 7, 8, 9); # ascending 9 | say [<] @a; # True 10 | 11 | my @b = (1, 2, 7, 3, 8, 9); # not quite strictly ascending 12 | say [<] @b; # False 13 | 14 | # bruce gray: 15 | # [op] @list 16 | # @list[0] op @list[1] op @list[2] 17 | # 3 + 5 18 | # [+] 3, 5 19 | say [+] 3, 5; # 8 20 | 21 | my @monsters = < blob tingler mothera wolfman garuda >; 22 | # my $status = [ eq ] @monsters; 23 | # say $status; 24 | -------------------------------------------------------------------------------- /notes/talks/data_math/O-thanks.org: -------------------------------------------------------------------------------- 1 | * That's all folks 2 | ** my "slides" are up at github 3 | *** https://github.com/doomvox/raku-study/tree/main/notes/talks/data_math 4 | 5 | ** More at the Raku Study Group on June 20th 6 | *** https://www.meetup.com/San-Francisco-Perl/events/278735631/ 7 | 8 | *** I post notifications at some mailing lists: 9 | **** perl6-users@perl.org, subscription info: 10 | https://lists.perl.org/list/perl6-users.html 11 | **** the sf perl list, subscription info: 12 | http://sf.pm.org/ 13 | 14 | ** you can reach me at: 15 | doomvox@gmail.com 16 | -------------------------------------------------------------------------------- /bin/2022nov20/messing_with_quote_immutable_strings.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # messing_with_quote_immutable_strings.raku 20 Nov 2022 4 | 5 | use v6; 6 | 7 | 8 | my $str1 := "garuda"; 9 | 10 | my $str2 = $str1; 11 | 12 | # $str2 = $str2.subst('garuda', 'rhodan'); 13 | $str2 = 'rhodan'; 14 | say $str2; # rhodan 15 | 16 | 17 | my $a = 1; 18 | say $a.WHAT; # (Int) 19 | say $a.VAR.WHAT; # (Scalar) 20 | say $a.VAR; # 1 21 | 22 | my $b = (1, 2); 23 | say $b.WHAT; # (List) 24 | say $b.VAR.WHAT; # (Scalar) 25 | say $b.VAR; # $(1, 2) 26 | -------------------------------------------------------------------------------- /bin/2023apr16/unixstackexchange_fortran_d_to_scientific_e_and_filter_wm_raku_oneliner.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # 16 Apr 2023 4 | 5 | # william michaels raku oneliner (his first try) 6 | # https://unix.stackexchange.com/a/742940/227738 7 | 8 | use v6; 9 | 10 | raku -e 'my @a; for lines.join("\n").split(/ \n /) { @a.push: %(.split("\n").[0].words.[2] => \ 11 | .split("\n")[1..*].map(*.words[0,4])>>.map(*.subst( / (\d+) (<[+-]>) /, {$0 ~ "e" ~ $1} ).subst(/D/, "e") )>>.Num) }; \ 12 | .raku.put for @a;' file 13 | 14 | 15 | -------------------------------------------------------------------------------- /bin/2025aug10/ranges_and_sequences-list_slices.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # ranges_and_sequences-list_slices.raku 10 Aug 2025 4 | 5 | use v6; 6 | 7 | my @monsters = < ankou araxxor borrokar damis delrith elvarg kalrag yuri >; ## www.runehq.com 8 | 9 | say @monsters[ 1 .. 3 ]; ## (araxxor borrokar damis) 10 | say @monsters[ 1 ... 3 ]; ## (araxxor borrokar damis) 11 | 12 | say @monsters[ 3 .. 1 ]; ## () 13 | say @monsters[ (1 .. 3).reverse ]; ## (damis borrokar araxxor) 14 | 15 | say @monsters[ 3 ... 1 ]; ## (damis borrokar araxxor) 16 | 17 | 18 | -------------------------------------------------------------------------------- /bin/2022nov20/bags_of_lists.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bags_of_lists.raku 20 Nov 2022 4 | 5 | use v6; 6 | 7 | my %bh = ( $(1,2), $(2,3), $(4,5) ).BagHash; 8 | say %bh; 9 | # {1 2 => 1, 2 3 => 1, 4 5 => 1} 10 | 11 | my %bh2 = ( $(1,2), $(2,3), $(4,5), $(1,2) ).BagHash; 12 | say %bh2; # {1 2 => 1, 2 3 => 1, 4 5 => 1} 13 | 14 | 15 | # say %bh.^methods; 16 | 17 | %bh.append( $(1,2) ); 18 | say %bh; 19 | # {1 2 => 1, 2 3 => 1, 4 5 => 1} 20 | 21 | say %bh{ $(1.2) }; # (Any) 22 | 23 | # %bh.push( $(1,2) ); 24 | # # Trailing item in Hash.push 25 | 26 | 27 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/Z3-random_raku.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # Z3-random_raku.raku 05 Jan 2022 4 | 5 | ## randomly choosing an element from an array 6 | my @cards = < jack_of_hearts 8_of_cups wheel_of_tech fool joker go_directly_to_jail three_wavy_lines death >; 7 | my $card = @cards.pick; 8 | say "card: $card"; 9 | 10 | ## creating a short string with random characters 11 | my $str = [~] ("a".."z").roll(3); 12 | say "str: $str"; 13 | 14 | ## Note that the "[~]" construct is 15 | ## "the reduction metaoperator" with string concatenation ("~") 16 | 17 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/Z4-trial-spy_via_ampersand.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # trial-spy_via_ampersand.pl6 20 Sep 2020 4 | 5 | ## You can call any routine as though it were a method by using 6 | ## an ampersand with the name: 7 | 8 | my @monsters = 9 | << godzilla blob mothera mechazilla tingler garuda gammera >>; 10 | 11 | # dd @monsters; 12 | 13 | say "result: ", @monsters.grep({ m/^g/ }).&spy.grep({ m/z/ }).map({ .uc }); 14 | 15 | sub spy { 16 | say "Spying on: ", callframe(1); 17 | dd @_; 18 | return @_; 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /bin/2021sep26/anon_var_vs_topic.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # anon_var_vs_topic.raku 13 Sep 2021 4 | 5 | use v6; 6 | 7 | # RAKU 8 | # Q: isn't this a bug? 9 | # Why is $++ acting as though I'm checking $_ there? 10 | 11 | # raku -e 'for 1 .. 100 { last if $++ > 20; say $_ if .is-prime; }' 12 | # 2 13 | # 3 14 | # 5 15 | # 7 16 | # 11 17 | # 13 18 | # 17 19 | # 19 20 | 21 | # for 1 .. 100 { 22 | for 101 .. 200 { 23 | last if $++ > 20; 24 | # say $_ if .is-prime; 25 | say $_; 26 | } 27 | 28 | 29 | 30 | # === 31 | # Author: doom@kzsu.stanford.edu 32 | 33 | -------------------------------------------------------------------------------- /bin/2024oct20/visibility_dynamics-ii.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # visibility_dynamics.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | say $*RAT-OVERFLOW; 8 | 9 | { 10 | my $*RAT-OVERFLOW = FatRat; 11 | say $*RAT-OVERFLOW; 12 | 13 | # ===SORRY!=== Error while compiling /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024oct20/visibility_dynamics.raku 14 | # Illegal post-declaration of dynamic variable '$*RAT-OVERFLOW'. Earlier 15 | # access must be written as 'CALLERS::<$*RAT-OVERFLOW>' if that's what you 16 | # meant. 17 | 18 | } 19 | 20 | say $*RAT-OVERFLOW; 21 | -------------------------------------------------------------------------------- /bin/2025jan05/sigiless.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # sigiless.raku 05 Jan 2025 4 | 5 | use v6; 6 | 7 | # my \degrees = pi / 180; 8 | # my \θ = 15 * degrees; 9 | 10 | 11 | sub hm { 12 | say "Hm...."; 13 | } 14 | 15 | hm; 16 | 17 | ## Hm.... 18 | 19 | 20 | my \hm = 'human'; 21 | say hm; # human 22 | 23 | say hm(); 24 | # Hm.... 25 | # True 26 | 27 | ## \hm = 'undaunted'; # Cannot modify an immutable Capture (\("human")) 28 | 29 | hm := 'bound!'; 30 | # Cannot bind to 'hm' because it is a term and terms cannot be rebound 31 | 32 | say hm; 33 | 34 | 35 | -------------------------------------------------------------------------------- /bin/2021oct24/try_catch_basics.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # try_catch_basics.raku 24 Oct 2021 4 | 5 | use v6; 6 | 7 | try { 8 | my $not_really_sensible = 1/0; 9 | say $not_really_sensible; 10 | 11 | CATCH { say "just forget about that problem"; .resume }; # This exception is not resumable 12 | # CATCH { default { say "CAUGHT: ", .Str; .resume } } 13 | } 14 | 15 | ## Would really like: 16 | ## .resume_really_and_truly_no_fooling 17 | 18 | say "won't get here"; ## doesn't happen 19 | 20 | 21 | 22 | # === 23 | # Author: doom@kzsu.stanford.edu 24 | 25 | -------------------------------------------------------------------------------- /bin/2025aug24/literal_list_array_indicies.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # literal_list_array_indicies.raku 24 Aug 2025 4 | 5 | use v6; 6 | 7 | my @m = << godzilla mothera frankenstein dorisday blob golem grendel triffids master >>; 8 | 9 | 10 | my @i = (1, 2, 3, 7, 8); 11 | say @m[ @i ]; # (mothera frankenstein dorisday triffids master) 12 | 13 | 14 | my @a = 1, 2, 3; 15 | my @b = 7, 8; 16 | 17 | say @m[ (@a, @b) ]; 18 | # ((mothera frankenstein dorisday) (triffids master)) 19 | 20 | say @m[ flat(@a, @b) ]; 21 | # (mothera frankenstein dorisday triffids master) 22 | 23 | -------------------------------------------------------------------------------- /bin/issues_3851_native_call_and_c_ints.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # issues_3851_native_call_and_c_ints.pl6 20 Dec 2020 4 | 5 | 6 | # Jeff is interested in this: 7 | # https://stackoverflow.com/questions/59209789/using-void-structs-in-raku-via-nativecall 8 | 9 | ## Make errors into warnings 10 | CATCH { default { say "CAUGHT: ", .Str; .resume } } 11 | 12 | use v6.d; 13 | use NativeCall; 14 | class simple is repr('CStruct') { 15 | has uint16 $.value; 16 | } 17 | 18 | my $simple = simple.new(:value(0xffff)); 19 | say "BROKEN!" if $simple.value ≠ 0xffff; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /bin/2024oct20/visibility_dynamics.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # visibility_dynamics.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | { 8 | say $*RAT-OVERFLOW; 9 | 10 | my $*RAT-OVERFLOW = FatRat; 11 | 12 | # ===SORRY!=== Error while compiling /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024oct20/visibility_dynamics.raku 13 | # Illegal post-declaration of dynamic variable '$*RAT-OVERFLOW'. Earlier 14 | # access must be written as 'CALLERS::<$*RAT-OVERFLOW>' if that's what you 15 | # meant. 16 | 17 | 18 | # say $*RAT-OVERFLOW; 19 | } 20 | 21 | #say $*RAT-OVERFLOW; 22 | -------------------------------------------------------------------------------- /bin/MultiDispatch/broken_a_is_for_arity.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # broken_a_is_for_airity.raku 25 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | multi talk_to_me ( $a ) { 9 | say "we got ONE argument"; 10 | } 11 | 12 | multi talk_tof_me ( $a ) { 13 | say "we got JUST ONE arg again"; 14 | } 15 | 16 | # multi talk_to_me ( *@args ) { 17 | # say "looks like more than two args"; 18 | # } 19 | 20 | talk_to_me( "hey" ); 21 | talk_to_me( "ho" ); 22 | 23 | # talk_to_me( "hey", "ho", "let's go" ); 24 | 25 | 26 | # we got ONE argument 27 | # we got ONE argument 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /bin/2025oct05/sub_as_method.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # sub_as_method.raku 05 Oct 2025 4 | 5 | use v6; 6 | 7 | sub spy { 8 | say $^a; 9 | return $^a; 10 | } 11 | 12 | 13 | my @numbers = < wuhn tew thuree foah fahv sex sevhun >; 14 | 15 | 16 | @numbers.map({ uc($_) }).map({ substr($_,1,1) }).say; 17 | # (U E H O A E E) 18 | 19 | @numbers.map({ uc($_) }).&spy.map({ substr($_,1,1) }).say; 20 | # (WUHN TEW THUREE FOAH FAHV SEX SEVHUN) 21 | # (U E H O A E E) 22 | 23 | 24 | ## 6.e has a "snitch": 25 | # https://docs.raku.org/routine/snitch 26 | 27 | 28 | 29 | ## tee? 30 | -------------------------------------------------------------------------------- /bin/Subtitles/.META: -------------------------------------------------------------------------------- 1 | Saturday April 26, 2025 7:02 PM 2 | /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/Subtitles/.META 3 | 4 | Code to play with crunching subtitles files: *.srt 5 | 6 | 7 | --- 8 | 9 | Some simple p5 code: 10 | 11 | /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2025apr06/subtitles_clean_spam_BUGGY.pl 12 | 13 | --- 14 | 15 | Earlier work of mine own: 16 | 17 | /home/doom/End/Cave/Eye/Notes/notes-subtitle_scrub 18 | /home/doom/End/Cave/SubtitlePeople/Wall/Subtitle-Scrub/bin/subtitle_scrub 19 | /home/doom/End/Cave/SubtitlePeople/Wall/Subtitle-Scrub/lib 20 | 21 | 22 | === 23 | -------------------------------------------------------------------------------- /bin/2024jan21/random_experiment_with_binding_to_hash.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # random_experiment_with_binding_to_hash.raku 21 Jan 2024 4 | 5 | use v6; 6 | 7 | 8 | 9 | { 10 | my %h; 11 | %h := 42; 12 | # ... 13 | my ($k, $v) = "a", 43; 14 | # die if %h{$k}:exists and %h{$k} != $v; ## better if this was automated 15 | %h{$k} := $v; 16 | 17 | # Died 18 | # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024jan21/bruce_gray.raku line 11 19 | 20 | say %h; # {a => 43} 21 | 22 | # doesn't die, allows change of value 23 | } 24 | -------------------------------------------------------------------------------- /bin/2024nov24/but_why.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # but_why.raku 15 Nov 2024 4 | 5 | use v6; 6 | 7 | #| Base class for magicians 8 | class Magician { 9 | has Int $.level; 10 | has Str @.spells; 11 | } 12 | 13 | #| Fight mechanics 14 | sub duel(Magician $a, Magician $b) { 15 | } 16 | #= Magicians only, no mortals. 17 | 18 | say Magician.WHY; # Base class for magicians 19 | say &duel.WHY.leading; # Fight mechanics 20 | say &duel.WHY.trailing; # Magicians only, no mortals. 21 | 22 | say "---"; 23 | say &duel.WHY; 24 | # Fight mechanics 25 | # Magicians only, no mortals. 26 | -------------------------------------------------------------------------------- /bin/2024nov24/roll_your_own_dynamic_var.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # roll_your_own_dynamic_var.raku 24 Nov 2024 4 | 5 | use v6; 6 | 7 | { 8 | my $*DOOM = "a"; 9 | dd( $*DOOM ); # Str $*DOOM = "a" 10 | 11 | dostuff(); # A 12 | 13 | } 14 | 15 | 16 | ## Q: what can you do with your own "dynamic var"? 17 | ## https://docs.raku.org/language/variables#The_*_twigil 18 | 19 | sub dostuff { 20 | say $*DOOM.uc; # Str $*DOOM = "a" # Dynamic variable $*DOOM not found 21 | 22 | # say $*NADA.uc; # Str $*DOOM = "a" ## Dynamic variable $*NADA not found 23 | 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /bin/2025may25/run_and_call_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # run_and_call_etc.raku 25 May 2025 4 | 5 | use v6; 6 | 7 | 8 | 9 | 10 | # external commands without shell: 11 | my $arg = 'Hello'; 12 | { 13 | my $captured = run('echo', $arg, :out).out.slurp; 14 | say $captured; 15 | } 16 | { 17 | my $captured = run(«echo "$arg"», :out).out.slurp; 18 | say $captured; 19 | } 20 | 21 | # using shell: 22 | { 23 | my $captured = shell("echo $arg", :out).out.slurp; 24 | say $captured; 25 | } 26 | { 27 | my $captured = qqx{echo $arg}; 28 | say $captured; 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /bin/MultiDispatch/a_is_for_arity.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # a_is_for_airity.raku 25 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | multi talk_to_me ( $a ) { 9 | say "we got ONE argument"; 10 | } 11 | 12 | multi talk_to_me ( $a, $b ) { 13 | say "we got TWO arguments"; 14 | } 15 | 16 | multi talk_to_me ( *@args ) { 17 | say "looks like more than two args"; 18 | } 19 | 20 | 21 | talk_to_me( "hey" ); 22 | talk_to_me( "hey", "ho" ); 23 | 24 | talk_to_me( "hey", "ho", "let's go" ); 25 | 26 | 27 | # we got ONE argument 28 | # we got TWO arguments 29 | # looks like more than two args 30 | 31 | -------------------------------------------------------------------------------- /bin/2021apr25/bg_idiom_assign_and_check_what_you_got.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bg_idiom_assign_and_check_what_you_got.raku 25 Apr 2021 4 | 5 | use v6; 6 | 7 | my @a = , , 42; 8 | for @a -> @z { 9 | say $++, ": ", @z.WHAT; 10 | } 11 | 12 | # 0: (List) 13 | # 1: (List) 14 | # Type check failed in binding to parameter '@z'; expected Positional but got Int (42) 15 | # in block at -e line 1 16 | 17 | 18 | 19 | 20 | 21 | 22 | # ## Make errors into warnings 23 | # CATCH { default { say "CAUGHT: ", .Str; .resume-force-just-do-it-stop-bugging-me-keep-going-you-idjit } } 24 | -------------------------------------------------------------------------------- /bin/2021sep26/hailstone_numbers.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # hailstone_numbers.raku 26 Sep 2021 4 | 5 | use v6; 6 | 7 | ## Bruce Gray 8 | 9 | sub hailstone($n) { $n, { $_ %% 2 ?? $_ div 2 !! $_ * 3 + 1 } ... 1 } 10 | 11 | my @h = hailstone(27); 12 | say "Length of hailstone(27) = {+@h}"; 13 | say ~@h; 14 | 15 | my $m = max ( (1..99_999).race.map: { +hailstone($_) => $_ } ); 16 | say "Max length {$m.key} was found for hailstone({$m.value}) for numbers < 100_000"; 17 | 18 | 19 | 20 | 21 | 22 | # ==== 23 | # sheet of cheats 24 | 25 | 26 | # === 27 | # Author: doom@kzsu.stanford.edu 28 | 29 | -------------------------------------------------------------------------------- /bin/2021apr25/dd.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # dd.raku 25 Apr 2021 4 | 5 | ## It's at least slightly disconcerting to the beginner, 6 | ## that the hash idiom a perl person is likely to use 7 | ## is echoed in a different form by dd. 8 | 9 | ## Q: should the output of .raku be used as a guide to approved idioms? 10 | 11 | use v6; 12 | 13 | my %hashola = whun => 1, tew => 2, thuree => 3; 14 | 15 | say %hashola; 16 | # {tew => 2, thuree => 3, whun => 1} 17 | 18 | dd %hashola; 19 | # Hash %hashola = {:tew(2), :thuree(3), :whun(1)} 20 | 21 | say %hashola.raku; 22 | # {:tew(2), :thuree(3), :whun(1)} 23 | -------------------------------------------------------------------------------- /bin/2022nov20/raku_hashes_compared_to_perl.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # raku_hashes_compared_to_perl.raku 20 Nov 2022 4 | 5 | use v6; 6 | 7 | 8 | my %response = ( success => 1, 9 | stuff => 'whateva', 10 | ); 11 | 12 | say %response{'success'}; 13 | ## 1 14 | 15 | ## say %response; 16 | 17 | say %response{ success() }; 18 | # ===SORRY!=== Error while compiling /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022nov20/raku_hashes_compared_to_perl.raku 19 | # Undeclared routine: 20 | # success used at line 16. Did you mean 'succeed'? 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /bin/2023oct22/can_has_cool.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # can_has_cool.raku 22 Oct 2023 4 | 5 | use v6; 6 | 7 | class MyWidget { 8 | has Numeric(Cool) $.size is rw; 9 | } 10 | 11 | my $obj = MyWidget.new( size => 3 ); 12 | dd( $obj ); 13 | 14 | my $obj2 = MyWidget.new( size => '666' ); 15 | dd( $obj2 ); 16 | 17 | my $obj3 = MyWidget.new( size => 'five' ); 18 | dd( $obj3 ); 19 | 20 | # MyWidget $obj3 = MyWidget.new(size => Failure.new(exception => X::Str::Numeric.new(source => "five", pos => 0, reason => "base-10 number must begin with valid digits or '.'"), backtrace => Backtrace.new)) 21 | 22 | 23 | -------------------------------------------------------------------------------- /notes/talks/file_metadata/file_metadata.org: -------------------------------------------------------------------------------- 1 | * File Metadata 2 | ** a rant in progress 3 | ** problems with the standard file system model 4 | *** 5 | 6 | ** naming components 7 | 8 | *** raku .parts and friends disappointing 9 | *** perl cpan module File::Basename 10 | 11 | If @suffixes are given each element is a pattern (either a string 12 | or a "qr//") matched against the end of the $filename. The 13 | matching portion is removed and becomes the $suffix. 14 | 15 | # On Unix returns ("baz", "/foo/bar/", ".txt") 16 | fileparse("/foo/bar/baz.txt", qr/\.[^.]*/); 17 | -------------------------------------------------------------------------------- /bin/2023apr16/rir_question_array_interpolation_in_quoted_strings.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # rir_question_array_interpolation_in_quoted_strings.raku 16 Apr 2023 4 | 5 | # Rob raised a question about interpolation into quoted strings 6 | 7 | use v6; 8 | 9 | # say "@.phooey"; 10 | # Variable @.phooey used where no 'self' is available 11 | 12 | my @a = [1,2,3]; 13 | say "@a[]"; # 1 2 3 14 | 15 | say "@[]"; # @[] 16 | 17 | say "@[].phooey"; # @[].phooey 18 | 19 | 20 | ## So, the '@.' is somekinda twigily thing to the parser? 21 | 22 | ## an oddity, not *too* bad as a LTA error-- gets you to the problem. 23 | 24 | -------------------------------------------------------------------------------- /bin/2023oct22/samemark.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # samemark.raku 22 Oct 2023 4 | 5 | ## https://docs.raku.org/type/Str#routine_samemark 6 | 7 | # Returns a copy of $string with the mark/accent information for 8 | # each character changed such that it matches the mark/accent of 9 | # the corresponding character in $pattern. 10 | 11 | say 'åäö'.samemark('aäo'); # aäo 12 | say 'åäö'.samemark('a'); # aao 13 | 14 | say samemark('Räku', 'a'); # Raku 15 | say samemark('aöä', ''); # aöä 16 | 17 | say "==="; 18 | 19 | say 'åäö'.samemark('xyz'); # aao 20 | say 'xyz'.samemark('åäö'); # x̊ÿz̈ 21 | 22 | 23 | -------------------------------------------------------------------------------- /bin/2025sep07/spurts_come_in_love.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # spurts_come_in_love.raku 07 Sep 2025 4 | 5 | use v6; 6 | 7 | my $fh = "/home/doom/tmp/Untitled_test_spurt".IO; 8 | "/home/doom/tmp/Untitled_input".IO.slurp.subst("Hello","Hi") andthen spurt($fh, $_, createonly => True); 9 | ## Failed to open file /home/doom/tmp/Untitled_test_spurt: File exists 10 | 11 | "/home/doom/tmp/Untitled36".IO.slurp.subst("Hello","Hi") andthen spurt($fh, $_, createonly => True); 12 | 13 | 14 | 15 | my $fh = "Untitled4_bak".IO; 16 | "Untitled4".IO.slurp.subst( :global, "Hello ", "Hi ") andthen spurt( $fh, $_, :createonly ); 17 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/K8-trial-http_useragent.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # trial-http_useragent.pl6 06 Oct 2019 4 | 5 | # Playing with an example from the Derek tutorial 6 | 7 | # Q: can I identify a re-direct? 8 | 9 | use HTTP::UserAgent; 10 | my $uA = HTTP::UserAgent.new; 11 | $uA.timeout = 10; 12 | my $url = "http://obsidianrook.com/resume.html"; 13 | my $response = $uA.get($url); 14 | my $dW; 15 | if $response.is-success { 16 | $dW = $response.content; 17 | } else { 18 | die $response.status-line; 19 | } 20 | 21 | for $dW.lines(10) -> $text { 22 | say $text; 23 | } 24 | 25 | say $dW.gist; 26 | -------------------------------------------------------------------------------- /bin/2024mar10/bruce_sort_naturally.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # bruce_sort_naturally.raku 10 Mar 2024 4 | 5 | use v6; 6 | 7 | sub naturally ( Str $s --> List ) { 8 | $s.split(:v, /\d+/).map({ +$_ // $_ }).cache 9 | } 10 | 11 | my @a = ; 12 | 13 | .say for @a.sort: &naturally; 14 | 15 | # sub naturally2 ( Str $s --> List ) { 16 | # $s.split(:v, /\d+/).map( * andthen +$_ // $_ ).cache 17 | # } 18 | 19 | # .say for @a.sort: &naturally2; 20 | -------------------------------------------------------------------------------- /bin/2022oct23/modgrid/jb_modgrid_02.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # jb_modgrid_02.raku 09 Oct 2022 4 | 5 | use v6; 6 | 7 | my $dat_loc = $*PROGRAM.parent.add('dat'); 8 | chdir( $dat_loc ); 9 | 10 | # my $file = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022oct23/modgrid/dat/warrior_weaponry.txt"; 11 | my $file = "warrior_weaponry.txt"; 12 | for $file.IO.lines -> $line { 13 | my @words = $line.split(/\s+/).reverse; 14 | my $data = @words[ 0 .. 4 ].reverse.join("\t"); 15 | my $string = @words[ 5 .. *-1 ].reverse.join(" "); 16 | my $output = $string ~ "\t" ~ $data; 17 | say $output; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /bin/2023mar26/william_michaels_identity.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # william_michaels_identity.raku 26 Mar 2023 4 | 5 | use v6; 6 | 7 | # $ raku 8 | # Welcome to Rakudo™ v2022.07. 9 | # Implementing the Raku® Programming Language v6.d. 10 | # Built on MoarVM version 2022.07. 11 | 12 | # To exit type 'exit' or '^D' 13 | # [0] > Nil === True 14 | # False 15 | # [1] > Nil === False 16 | # False 17 | # [2] > Nil === Nil 18 | # True 19 | # [3] > exit 20 | 21 | 22 | ## SELECT value, count(*) FROM data GROUP BY value; 23 | 24 | ## value identity 25 | ## === 26 | ## container identity (( is that a screwy name? )) 27 | ## =:= 28 | -------------------------------------------------------------------------------- /bin/DeepMap/disassemble_hash_reassemble_into_copy.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # disassemble_hash_reassemble_into_copy.raku 28 Jan 2025 4 | 5 | use v6; 6 | 7 | my %threat = ( godzilla => 8, mothera => 6, rhodan => 5, tingler => 3, wolfman => 3, dracula => 4, horta => 1, blob => 3 ); 8 | say %threat; 9 | # {blob => 3, dracula => 4, godzilla => 8, horta => 1, mothera => 6, rhodan => 5, tingler => 3, wolfman => 3} 10 | 11 | my %new_threat = Hash.new.STORE: %threat.keys, %threat.values, :INITIALIZE; 12 | say %new_threat; 13 | # {blob => 3, dracula => 4, godzilla => 8, horta => 1, mothera => 6, rhodan => 5, tingler => 3, wolfman => 3} 14 | -------------------------------------------------------------------------------- /bin/2021jun20/element_membership.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # element_membership.raku 20 Jun 2021 4 | 5 | use v6; 6 | 7 | # "in" 8 | 9 | # ∈ ∋ 10 | # (cont) (elem) 11 | 12 | my @numbers = < wuhn tew thuree foah fahv sex sevhun >; 13 | my $value = 'tew'; 14 | 15 | # Is the value in the @numbers array? 16 | my $set = @numbers.Set; 17 | say $set; # Set(fahv foah sevhun sex tew thuree wuhn) 18 | if ($value (elem) $set) { 19 | say "yes it is"; # yes it is 20 | } else { 21 | say "no"; 22 | } 23 | 24 | # another way of checking: 25 | if $value eq any( @numbers ) { 26 | say "meep"; # meep 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /bin/2023apr30/jj_merelo_grep_csv.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # jj_merelo_grep_csv.raku 30 Apr 2023 4 | 5 | use v6; 6 | 7 | ## From JJ Mereleo's Raku Cookbook (Chapter 3) 8 | ## https://www.nal.usda.gov/human-nutrition-and-food-safety/nutrient-lists-standard-reference-legacy-2018 9 | 10 | ## my $data_file = "/home/doom/Dust/Data/all_downloads_apr_2023/nutrient.csv"; 11 | my $data_file = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2023apr30/data/nutrients_merelo.csv"; 12 | 13 | .say for $data_file.IO.lines.grep: { 14 | my @data = $_.split('","'); 15 | $_ if @data[2] eq "Protein" and @data[4] > 70 and @data[5] ~~ /^g/ 16 | } 17 | -------------------------------------------------------------------------------- /bin/2025aug24/backward_ranges_empty_sets.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # backward_ranges_empty_sets.raku 24 Aug 2025 4 | 5 | use v6; 6 | 7 | 8 | for (3..5) {.say; } 9 | # 3 10 | # 4 11 | # 5 12 | say "---"; 13 | for (5..3) {.say; } 14 | say "---"; 15 | ## --- 16 | ## --- 17 | 18 | ## Rlang allows reverse ranges, but not Raku 19 | # > 1:10 20 | # [1] 1 2 3 4 5 6 7 8 9 10 21 | # > 10:1 22 | # [1] 10 9 8 7 6 5 4 3 2 1 23 | 24 | for (5..3).reverse {.say; } 25 | ## Q: how do you reverse a range, anyway? 26 | 27 | 28 | 29 | ### 30 | ### Aside, shocking isn't it? 31 | ### Seq objects are not valid endpoints for Ranges 32 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/E1-math_on_arbitrary_parallel_structures_in_perl5.org: -------------------------------------------------------------------------------- 1 | * but can you math on *arbitrary* parallel datastructures? 2 | ** do recursive descent of two structures, creating a third as you go 3 | *** perlish structures have *two* main types of aggregates: array and hashes 4 | *** handling "holes" in one side requires looking at the other to get type 5 | ** perl solution 6 | *** Data::Math, a module on cpan/github 7 | **** cpan 8 | ***** https://metacpan.org/pod/Data::Math 9 | ***** https://metacpan.org/pod/Scalar::Classify 10 | **** github 11 | ***** https://github.com/doomvox/data-math 12 | ***** https://github.com/doomvox/scalar-classify 13 | -------------------------------------------------------------------------------- /bin/2024oct20/rats_scraping_the_barrel.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # rats_scraping_the_barrel.raku 24 Nov 2024 4 | 5 | use v6; 6 | 7 | ## Rat 1/3, but 1/(2⁶⁴+) 8 | 9 | { 10 | my $a = 1 / (2⁶⁴ - 1); 11 | say $a; # 0.000000000000000000054 12 | say $a.^name; # Rat 13 | } 14 | 15 | 16 | { 17 | my $a = 1 / (2⁶⁴); 18 | say $a; # 5.421010862427522e-20 19 | say $a.^name; # Num 20 | } 21 | 22 | 23 | 24 | { 25 | my $a = Rat.new( 1, 2⁶⁴ ); 26 | say $a; # 0.000000000000000000054 27 | say $a.^name; # Rat 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /bin/2025apr27/smiley_sigs.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # smiley_sigs.raku 27 Apr 2025 4 | 5 | use v6; 6 | ## Bruce example, doing signature introspection: 7 | 8 | ## raku -e 'sub foo ( Int:D $n ) {...}; my $p1 = &foo.signature.params[0]; say $p1.type; say $p1.modifier;' 9 | 10 | sub foo ( Int:D $n ) {...}; 11 | 12 | my $p1 = &foo.signature.params[0]; 13 | say $p1.type; # (Int) 14 | say $p1.modifier; # :D 15 | 16 | ## So this thinks of the type as seperate from the modifier, the smiley 17 | 18 | 19 | sub bar ( Nil:D $n ) {...}; 20 | 21 | my $p1 = &bar.signature.params[0]; 22 | say $p1.type; # (Int) 23 | say $p1.modifier; # :D 24 | -------------------------------------------------------------------------------- /bin/catching_errors_converting_to_warning.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # catching_errors_converting_to_warning.pl6 20 Dec 2020 4 | 5 | 6 | use v6; 7 | 8 | # Yary hint: 9 | # Experiment to turn ALL failures into warnings— at top level, “CATCH { default { .note; .resume } }” 10 | 11 | CATCH { default { say "CAUGHT: ", .Str; .resume } } 12 | 13 | say '---'; 14 | # { 15 | # say 3/0; # This exception is not resumable 16 | 17 | subset Trekoids of Str where * eq any(<< Kirk Spock McCoy Scotty Uhuru Chapel Chekov Sulu >>); 18 | my Trekoids $name; 19 | $name = "Bozo"; 20 | # } 21 | 22 | say '---'; 23 | # { 24 | say "still alive"; 25 | # } 26 | -------------------------------------------------------------------------------- /bin/2022feb27/rob_classify_issue.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # rob_classify_issue.raku 27 Feb 2022 4 | 5 | use v6; 6 | 7 | 8 | ## Rob makes the point that this error message may be LTA 9 | 10 | # say (3).classify( 3, 4, 5, 6, 7, 8); 11 | 12 | # Cannot resolve caller classify(Int:D: Int:D, Int:D, Int:D, Int:D, Int:D, Int:D); none of these signatures match: 13 | # ($: *%_) 14 | # ($: Whatever, *%_) 15 | # ($: $test, :$into!, :&as, *%_) 16 | # ($: $test, :&as, *%_) 17 | # in block at line 1 18 | 19 | 20 | ## works for some definition of working: 21 | say (3, 4, 5, 6, 7, 8).classify( {$_~~3} ); 22 | # {False => [4 5 6 7 8], True => [3]} 23 | -------------------------------------------------------------------------------- /bin/2021oct10/anon_var_vs_topic.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # anon_var_vs_topic.raku 13 Sep 2021 4 | 5 | ## I thought I was seeing weird behavior here, but don't know what I was thinking now. 6 | 7 | use v6; 8 | 9 | # RAKU 10 | # Q: isn't this a bug? 11 | # Why is $++ acting as though I'm checking $_ there? 12 | 13 | # raku -e 'for 1 .. 100 { last if $++ > 20; say $_ if .is-prime; }' 14 | # 2 15 | # 3 16 | # 5 17 | # 7 18 | # 11 19 | # 13 20 | # 17 21 | # 19 22 | 23 | # for 1 .. 100 { 24 | for 101 .. 200 { 25 | last if $++ > 20; 26 | # say $_ if .is-prime; 27 | say $_; 28 | } 29 | 30 | 31 | 32 | # === 33 | # Author: doom@kzsu.stanford.edu 34 | 35 | -------------------------------------------------------------------------------- /bin/2021oct24/raku_code_ex_generic_case.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # raku_code_ex_generic_case.raku 24 Oct 2021 4 | 5 | use v6; 6 | 7 | sub foo { 8 | ... 9 | } 10 | sub bar { 11 | .... 12 | } 13 | 14 | my $thingie = foo + bar; 15 | 16 | my $thingie = first_val + second_val; 17 | 18 | 19 | ## 20 | 21 | sub check { 22 | ... 23 | } 24 | sub retry { 25 | .... 26 | } 27 | 28 | my $thingie = check + retry: 29 | 30 | 31 | == 32 | 33 | sub my_check_routine { 34 | ... 35 | } 36 | sub my_retry_routine { 37 | .... 38 | } 39 | 40 | my $thingie = my_check_routine + my_retry_routine; 41 | 42 | 43 | # === 44 | # Author: doom@kzsu.stanford.edu 45 | 46 | -------------------------------------------------------------------------------- /bin/2022mar27/comb.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # comb.raku 26 Mar 2022 4 | 5 | use v6; 6 | 7 | say "abc".comb; # (a b c) 8 | 9 | for "abc".comb -> $c { 10 | say "$c"; 11 | } 12 | # a 13 | # b 14 | # c 15 | say "---"; 16 | 17 | say 333.comb; # (3 3 3) 18 | 19 | for 123.comb -> $d { 20 | say $d; 21 | } 22 | # 1 23 | # 2 24 | # 3 25 | 26 | say "---"; 27 | my $n = 637; 28 | for $n.comb -> $d { 29 | say $d; 30 | } 31 | # 6 32 | # 3 33 | # 7 34 | 35 | $n = 369; 36 | say $n.WHAT; # (Int) 37 | say so $n ~~ m/<[6]>/; 38 | # True 39 | say $n.WHAT; # (Int) 40 | say "---"; 41 | for $n.comb -> $d { 42 | say $d; 43 | } 44 | # 3 45 | # 6 46 | # 9 47 | 48 | 49 | -------------------------------------------------------------------------------- /bin/2023apr30/jj_merelo_grep_csv-text_csv.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # jj_merelo_grep_csv.raku 30 Apr 2023 4 | 5 | use v6; 6 | use Text::CSV; 7 | 8 | ## From JJ Mereleo's Raku Cookbook (Chapter 3) 9 | ## https://www.nal.usda.gov/human-nutrition-and-food-safety/nutrient-lists-standard-reference-legacy-2018 10 | 11 | ## my $data_file = "/home/doom/Dust/Data/all_downloads_apr_2023/nutrient.csv"; 12 | my $data_file = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2023apr30/data/nutrients_merelo.csv"; 13 | 14 | .say for $data_file.IO.lines.grep: { 15 | my @data = $_.split('","'); 16 | $_ if @data[2] eq "Protein" and @data[4] > 70 and @data[5] ~~ /^g/ 17 | } 18 | -------------------------------------------------------------------------------- /bin/2023may21/range_bounds_method.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # range_bounds_method.raku 21 May 2023 4 | 5 | use v6; 6 | 7 | my $r1 = 1 .. 5; # 1 <= $x <= 5 8 | my $r2 = 1^.. 5; # 1 < $x <= 5 9 | 10 | say $r1.bounds; 11 | say $r2.bounds; 12 | # (1 5) 13 | # (1 5) 14 | 15 | # bruce gray points out that the Range is *continuous*, not discrete (integers): 16 | 17 | # raku -e 'my Range $r = 1 ^..^ 5; say $_ ~~ $r for 1, 5, 6' 18 | # raku -e 'my Range $r = 1 ^..^ 5; say $_ ~~ $r for 1, 1.5, 4.5, 5, 6' 19 | 20 | say $r1.int-bounds; # (1 5) 21 | say $r2.int-bounds; # (2 5) 22 | 23 | 24 | say $r1.min, ' ', $r1.max; # 1 5 25 | say $r2.min, ' ', $r2.max; # 1 5 26 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/C5-DataMath/B-intro-hash_subtraction.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # B0-intro-hash_subtraction.pl June 9, 2021 3 | 4 | use 5.10.0; 5 | use warnings; 6 | use strict; 7 | 8 | { 9 | my (%gross, %costs, %net); 10 | 11 | %gross = ( de => 2345.37, 12 | es => 1238.99, 13 | us => 1.98, 14 | ); 15 | %costs = ( de => 35.00, 16 | es => 259.11, 17 | us => 666.66, 18 | ); 19 | 20 | %net = %gross - %costs; ## DOESN'T WORK 21 | 22 | } 23 | 24 | ## Clear what that line *should* do 25 | ## pop quiz: what does it actually do? 26 | 27 | -------------------------------------------------------------------------------- /bin/2024feb04/subs_and_passing_to_generic_array_at_underscore.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # subs_and_passing_to_generic_array_at_underscore.raku 04 Feb 2024 4 | 5 | use v6; 6 | 7 | 8 | ## in Raku you *can* pass a list to @_ 9 | { 10 | sub action { 11 | say @_; 12 | } 13 | action(1,2); # [1 2] 14 | } 15 | 16 | say "==="; 17 | ## you can do this 18 | { 19 | sub foo { 20 | my ($x, $y) = @_; 21 | say "x: $x, y: $y"; 22 | } 23 | foo( 5, 7 ); # x: 5, y: 7 24 | } 25 | 26 | say "---"; 27 | ## but we almost always would do this: 28 | { 29 | sub foo ($x, $y) { 30 | say "x: $x, y: $y"; 31 | } 32 | foo( 5, 7 ); # x: 5, y: 7 33 | } 34 | -------------------------------------------------------------------------------- /bin/modulus_operators.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # modulus_operators.pl6 13 Dec 2020 4 | 5 | 6 | use v6; 7 | 8 | my $a = 12; 9 | my $b = 4; 10 | 11 | say $a % $b; # 0 12 | say $a %% $b; # True 13 | 14 | say !( $a % $b ); # True 15 | 16 | for 0..100 -> $i { 17 | say "hey $i" if $i %% 25; 18 | } 19 | # hey 0 20 | # hey 25 21 | # hey 50 22 | # hey 75 23 | # hey 100 24 | 25 | 26 | # say 0 %% 0; 27 | # Attempt to divide by zero using infix:<%%> 28 | # in block at /home/doom/End/Cave/Perl6/Wall/raku-study/bin/modulus_operators.pl6 line 23 29 | 30 | for 0..5 -> $i { 31 | say "hey $i" if $i !%% 2; 32 | } 33 | # hey 1 34 | # hey 3 35 | # hey 5 36 | 37 | -------------------------------------------------------------------------------- /notes/talks/data_math/B-intro-hash_subtraction.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # B0-intro-hash_subtraction.pl June 9, 2021 3 | 4 | use 5.10.0; 5 | use warnings; 6 | use strict; 7 | $|=1; 8 | use Data::Dumper; 9 | 10 | { 11 | my (%gross, %costs, %net); 12 | 13 | %gross = ( de => 2345.37, 14 | es => 1238.99, 15 | us => 1.98, 16 | ); 17 | %costs = ( de => 35.00, 18 | es => 259.11, 19 | us => 666.66, 20 | ); 21 | 22 | %net = %gross - %costs; ## DOESN'T WORK 23 | 24 | } 25 | 26 | ## Clear what that line *should* do 27 | ## pop quiz: what does it actually do? 28 | 29 | -------------------------------------------------------------------------------- /notes/talks/data_math/Old/M-thanks.org: -------------------------------------------------------------------------------- 1 | * That's all folksen 2 | ** my "slides" are up at github 3 | *** https://github.com/doomvox/raku-study/tree/main/notes/talks/data_math 4 | 5 | ** Once again: I'll talk more about this at the Raku Study Group on June 20th 6 | *** https://www.meetup.com/San-Francisco-Perl/ 7 | *** I also post notifications at some mailing lists: 8 | **** perl6-users@perl.org, subscription info: 9 | https://lists.perl.org/list/perl6-users.html 10 | **** the sf perl list, subscription info: 11 | http://sf.pm.org/ 12 | **** perl6-users mailing list archive 13 | https://www.nntp.perl.org/group/perl.perl6.users/ 14 | 15 | 16 | ** you can reach me at: 17 | doomvox@gmail.com 18 | -------------------------------------------------------------------------------- /bin/2023aug06/hash_definition_quirks.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # hash_definition_quirks.raku 06 Aug 2023 4 | 5 | use v6; 6 | 7 | 8 | ## https://stackoverflow.com/questions/44101411/is-that-a-raku-hash-or-block 9 | 10 | 11 | { 12 | my $color-name-to-rgb = { 13 | 'red' => 'FF0000', 14 | }; 15 | 16 | put $color-name-to-rgb.^name; # Hash 17 | say $color-name-to-rgb; # FF0000 18 | } 19 | 20 | { 21 | my $color-name-to-rgb = { 22 | 'red', 'FF0000', 23 | }; 24 | put $color-name-to-rgb.^name; # Block 25 | say $color-name-to-rgb; # Type Block does not support associative indexing. 26 | 27 | 28 | } 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /bin/2025jan05/sigil_divisor.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # sigil_divisor.raku 05 Jan 2025 4 | 5 | use v6; 6 | 7 | { 8 | my \degrees = pi / 180; 9 | say degrees; # 0.017453292519943295 10 | } 11 | 12 | 13 | { 14 | my \deg_per_rad = 180; 15 | my \degrees = pi / deg_per_rad; 16 | say degrees; # 0.017453292519943295 17 | } 18 | 19 | 20 | { 21 | use Physics::Constants; 22 | use Physics::Measure :ALL; 23 | 24 | my \λ = 2.5nm; 25 | my \ν = c / λ; 26 | 27 | say "Frequency of photon (ν) is " ~ν.norm; #119.92 petahertz 28 | } 29 | 30 | # 31 | # OUR::{'&' ~ $name} := sub { Measure.new("{$const.value} {$const.defn}") }; 32 | # 33 | -------------------------------------------------------------------------------- /bin/2025jan05/third_max.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # third_max.raku 05 Jan 2025 4 | 5 | use v6; 6 | 7 | ## An old weekly challenge problem was the "third maximum" 8 | ## doing it with the triangle operator 9 | 10 | { say [\max] (); # () 11 | } 12 | 13 | { say [max] (); # -Inf 14 | } 15 | 16 | say "==="; 17 | 18 | { 19 | my @n = 9, 3, 137, 23, 13, 27, 64; 20 | say @n; 21 | say '---'; 22 | say [\max] @n; 23 | ## [9 3 137 23 13 27 64] 24 | say '---'; 25 | say [\min] @n; 26 | ## 27 | 28 | say ([\max] @n)[2]; # 137, wrong answer 29 | } 30 | 31 | { 32 | my @n = 9, 3, 137, 23, 13, 27, 64; 33 | say ( @n.sort )[2]; # 13 34 | } 35 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/A1-title_page.txt: -------------------------------------------------------------------------------- 1 | 2 | Januray 6, 2022 3 | 4 | 5 | Some Adventures with Raku over the Last Year 6 | 7 | 8 | Joseph Brenner 9 | http://obsidianrook.com/doomfiles 10 | 11 | I'm "doom" or "doomvox" in various places (github, cpan, gmail). 12 | (I was a college radio DJ: "The Voice of Doom" at KZSU.) 13 | 14 | I run the SF Perl "Raku Study Group" (next one on January 16th) 15 | https://www.meetup.com/San-Francisco-Perl/ 16 | 17 | Note: the "slides" for this talk will eventually be published here: 18 | 19 | https://github.com/doomvox/raku-study/notes/talks/new_year_raku/ 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /bin/2021jan24/grammar_example_from_tutorial-poor_thor_is_mighty.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # 2021jan24-grammar_example_from_tutorial.pl6 24 Jan 2021 4 | 5 | use v6; 6 | 7 | ## Example from: 8 | ## https://docs.raku.org/language/grammar_tutorial 9 | 10 | grammar G { 11 | token TOP { .* } 12 | token thingy { 'Þor' } 13 | } 14 | 15 | my $match = G.parse( "Þor is mighty" ); 16 | say $match.raku; 17 | ## Match.new(:orig("Þor is mighty"), :from(0), :pos(13), :hash(Map.new((:thingy(Match.new(:orig("Þor is mighty"), :from(0), :pos(3))))))) 18 | 19 | say $/.raku; 20 | # Match.new(:orig("Þor is mighty"), :from(0), :pos(3)) 21 | 22 | say $/; # 「Þor」 23 | 24 | -------------------------------------------------------------------------------- /bin/2021jan24/substitution_returns_a_match.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # 2021jan24-substitution_returns_a_match.pl6 24 Jan 2021 4 | 5 | use v6; 6 | 7 | { 8 | my $str = 'old string'; 9 | my $ret = $str ~~ s/o .+ d/new/; 10 | say $str; # new string 11 | 12 | say $ret; # 「old」 13 | 14 | dd $ret; 15 | # Match $ret = Match.new(:orig("old string"), :from(0), :pos(3)) 16 | 17 | ## No information on what was substituted ("new") 18 | } 19 | 20 | { # bruce gray variant: 21 | say "---"; 22 | my $str = 'old string'; 23 | my $saved; 24 | my $ret = $str ~~ s/o .+ d/{$saved = 'new'}/; 25 | say $str; # new string 26 | say $saved; # new 27 | } 28 | -------------------------------------------------------------------------------- /bin/2022jul24/gather.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # gather.raku 24 Jul 2022 4 | 5 | use v6; 6 | 7 | my %h = gather { take "foo" => 1; take "bar" => 2}; 8 | say %h; # {bar => 2, foo => 1} 9 | 10 | # === 11 | 12 | # rob ransbottom is interested in an issue with gather 13 | 14 | my @monsters = < ankou araxxor borrokar damis delrith elvarg kalrag yuri >; ## www.runehq.com 15 | # Iteration without gather/take 16 | for @monsters -> $m { 17 | say "monster: $m"; 18 | }; 19 | 20 | 21 | my @a = 22 | gather 23 | # { 24 | for @monsters -> $m { 25 | take $m if $m.chars > 6; 26 | } 27 | # } 28 | # ; 29 | 30 | say @a; # [araxxor borrokar delrith] 31 | 32 | -------------------------------------------------------------------------------- /bin/2021jul11/exporting_a_sub.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # exporting_a_sub.raku 10 Jul 2021 4 | 5 | use v6; 6 | 7 | # from the docs for "is export" trait: 8 | 9 | module Foo { 10 | sub double($x) is export { 11 | 2 * $x 12 | } 13 | } 14 | 15 | import Foo; # makes sub double available 16 | say double 21; # 42 (( Works )) 17 | 18 | 19 | ## Using import to pull something in from another file doesn't seem to work, 20 | ## but just saying "use" seems to do imports, even without :ALL 21 | 22 | use lib $*PROGRAM.parent.add('../../lib'); 23 | # import Data::Stub; # Could not find module Data::Stub to import symbols from 24 | use Data::Stub; 25 | say whun; ## 1 26 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/Z2-random_perl.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 2022/01/05 23:09:35 3 | 4 | use 5.10.0; 5 | use warnings; 6 | use strict; 7 | 8 | =head1 NAME 9 | 10 | Z2-random_perl.pl 11 | 12 | =head1 DESCRIPTION 13 | 14 | Some simple examples using randomness in perl. 15 | (1) picking an element; (2) generating a string 16 | 17 | =cut 18 | 19 | ## randomly choosing an element from an array 20 | my @words = qw( accomplice latent sportsmen glimpses jagged ); 21 | my $word = $words[ int( rand( $#words+1 ) ) ]; 22 | say $word; 23 | 24 | ## creating a short string of random characters 25 | my $str = join '', map{ chr( int( rand( 26 ) ) + 65 ) } 0..2; 26 | say $str; 27 | 28 | 29 | -------------------------------------------------------------------------------- /bin/2023jul23/hash_keys_with_spaces.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # hash_keys_with_spaces.raku 12 Jul 2023 4 | 5 | use v6; 6 | 7 | { 8 | my %threat_level = godzilla => 9, mothera => 7, rhodan => 7, tingler => 5, wolfman => 5; 9 | say %threat_level; 10 | 11 | say %threat_level{'godzilla'}; # 9 12 | say %threat_level; # 9 13 | 14 | } 15 | 16 | { # keys with embedded spaces: 17 | my %threat_level = godzilla => 9, 'united snakes' => 11, horta => 1; 18 | say %threat_level; 19 | say %threat_level{'united snakes'}; # 11 20 | # oops: 21 | say %threat_level<'united snakes'>; # ((Any) (Any)) 22 | # fix 23 | say %threat_level<<'united snakes'>>; # 11 24 | } 25 | -------------------------------------------------------------------------------- /notes/talks/multidispatch_vs_case/intro.txt: -------------------------------------------------------------------------------- 1 | b 2 | 3 | 4 | 5 | 6 | September 27, 2021 7 | 8 | 9 | 10 | Case statements (given/when) 11 | vs. Multi-dispatch in Raku 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /bin/2021oct24/docs_try_catch_ex.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # docs_try_catch_ex.raku 24 Oct 2021 4 | 5 | use v6; 6 | 7 | my $error-code = "333"; 8 | sub bad-sub { # always throws an error 9 | die "Something bad happened"; 10 | } 11 | try { 12 | ## my 13 | $error-code = "111"; 14 | bad-sub; 15 | $error-code = "666"; # we won't see this change 16 | 17 | CATCH { 18 | default { 19 | say "Error $error-code ", .^name, ': ',.Str; 20 | .resume; 21 | } 22 | } 23 | } 24 | say $error-code; # back to the beginning, I think: 333 25 | 26 | 27 | # OUTPUT: «Error 111 X::AdHoc: Something bad happened␤» 28 | # === 29 | # Author: doom@kzsu.stanford.edu 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /t/Deepmap/deepmap_preserve_untouched_hash_elements.t: -------------------------------------------------------------------------------- 1 | use v6; 2 | use Test; 3 | 4 | plan 2; 5 | 6 | =begin description 7 | 8 | This test explores a bug reported as issue NNNN. 9 | 10 | =end description 11 | 12 | my @data = ( 13 | { n => 1, a => 'alpha', }, 14 | { n => 2, a => 'beta', }, 15 | { n => 3, a => 'gamma', }, 16 | { n => 4, a => 'delta', }, 17 | ); 18 | 19 | my @expected = ({a => 'alpha', n => 11}, {a => 'beta', n => 12}, {a => 'gamma', n => 13}, {a => 'delta', n => 14}); 20 | 21 | { 22 | my @new_data = @data.deepmap({$_ ~~ Numeric ?? $_+10 !! $_ }); 23 | is-deeply( @new_data, @expected, "Testing with explicit handling of all values." ); 24 | } 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /bin/2022dec18/negatives_not_lexically_literal.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # negatives_not_lexically_literal.raku 18 Dec 2022 4 | 5 | use v6; 6 | 7 | 8 | ## bruce gray example 9 | ## raku -e 'say -1²' 10 | 11 | say -1²; 12 | # -1 13 | 14 | say - 1²; 15 | # -1 16 | 17 | say (- 1)²; 18 | # 1 19 | 20 | # marton: 21 | say -1.succ; 22 | # -2 23 | 24 | say - 1.succ; 25 | # -2 26 | 27 | say (-1).succ; 28 | # 0 29 | 30 | 31 | ## bruce 32 | # raku -e 'sub foo ( Int --> <-1/1> ) {}; say foo(5);' 33 | 34 | say "==="; 35 | { 36 | sub foo ( Int --> <-1/1> ) {}; 37 | say foo(5); # -1 38 | } 39 | 40 | # { 41 | # sub foo ( Int --> <-1> ) {}; ## Malformed return value ((???)) 42 | # say foo(5); # -1 43 | # } 44 | 45 | -------------------------------------------------------------------------------- /bin/2025jan05/rw_var.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # rw_var.raku 05 Jan 2025 4 | 5 | use v6; 6 | 7 | 8 | # my $changeable = 'seasons' is rw; 9 | 10 | ## my $changeable is rw = 'seasons'; # Can't use unknown trait 'is' -> 'rw' in variable declaration. 11 | 12 | ## my $changeable is ro = 'seasons'; # Can't use unknown trait 'is' -> 'ro' in variable declaration. 13 | 14 | ## confusing because has syntax works, albiet only in a class: 15 | 16 | has $.changeable is ro = 'seasons'; 17 | ## You cannot declare attribute '$changeable' here; maybe you'd like a class or a role? 18 | ## You cannot declare attribute '$.changeable' here; maybe you'd like a class or a role? 19 | 20 | ## So: no easy way to declare a ro var? 21 | 22 | -------------------------------------------------------------------------------- /bin/2022jul24/matches_dollar_parens_addsign_hyper.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # matches_dollar_parens_addsign_hyper.raku 24 Jul 2022 4 | 5 | # Department of "Oh, I forgot about that" 6 | 7 | use v6; 8 | 9 | # https://raku.org/archive/doc/design/apo/A05.html 10 | # RFC 071: Variable-length lookbheind 11 | 12 | # Update: 13 | # $() now represents the entire matched string, 14 | # the match object is now $/, 15 | # a list of all beginnings is returned by the 16 | # hyperoperator @()».beg. 17 | 18 | # Hm? 19 | # But note that string positions are not necessarily integers in Perl 20 | # 6. They are tagged with the units of the string, so that you can't 21 | # inadvertently mix byte, codepoint, or grapheme offsets. 22 | 23 | -------------------------------------------------------------------------------- /bin/2024jun30/shitov_variant_via_tim.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # shitov_variant_via_tim.raku 30 Jun 2024 4 | 5 | use v6; 6 | 7 | say (^10); # ^10 8 | 9 | my @a = (^10); 10 | say @a[5]; # 5 11 | 12 | say @a.list; # [0 1 2 3 4 5 6 7 8 9] 13 | 14 | say "==="; 15 | 16 | # Tim Schafer, working from code examples by Andrew Shitov: 17 | # https://andrewshitov.com/2019/09/09/printing-a-list-of-prime-numbers-using-perl-6/ 18 | 19 | say ((^100).grep: *.is-prime)[^27]; 20 | # (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Nil Nil) 21 | 22 | ## more technically correct (though same results) 23 | say ((1..100).grep: *.is-prime)[^25]; 24 | # (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97) 25 | -------------------------------------------------------------------------------- /bin/json_comparator_worthington.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # json_comparator_worthington.pl6 08 Jul 2018 4 | 5 | ## Tests two JSON files for equality, parsing them in parallel. 6 | ## A code example by Jonathan Worthington 7 | 8 | use v6; 9 | 10 | use JSON::Tiny; 11 | sub MAIN($file1, $file2) { 12 | my $parsing1 = start from-json( slurp( $file1 )); 13 | my $parsing2 = start from-json( slurp( $file2 )); 14 | 15 | say $parsing1.^name; # Promise 16 | 17 | my ($parsed1, $parsed2) = await $parsing1, $parsing2; 18 | say $parsed1 eqv $parsed2 19 | ?? 'Files contain identical JSON' 20 | !! 'Files contain different JSON'; 21 | } 22 | 23 | # Author: Jonathan Worthington 24 | # Typist: doom@kzsu.stanford.edu 25 | 26 | -------------------------------------------------------------------------------- /bin/2021sep12/pandigital_prime_rosettacode.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # pandigital_prime_rosettacode.pl6 12 Sep 2021 4 | 5 | use v6; 6 | 7 | # http://rosettacode.org/wiki/Pandigital_prime#Raku 8 | 9 | # Bruce Gray solution: 10 | say max (1..7).map: -> $size { 11 | |(1..$size).permutations».join.grep(&is-prime); 12 | } # 7652413 13 | 14 | say max (1..7).map( -> $size { 15 | | (1..$size).permutations».join.grep(&is-prime); 16 | } 17 | ); # 7652413 18 | 19 | say max (1..7).map( { 20 | my $size = $_; 21 | (1..$size).permutations».join.grep(&is-prime); 22 | } 23 | ).flat; # 7652413 24 | 25 | -------------------------------------------------------------------------------- /bin/2022mar27/werewolf_primes-02-via_perl_phasehunt_fullmoon_script.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # using_perl_script_from_raku.raku 27 Mar 2022 4 | 5 | use v6; 6 | 7 | my $prog = '/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022mar27/phasehunt_fullmoon.pl'; 8 | my $captured = run($prog, :out).out.slurp.split("\n"); 9 | for $captured.list -> $n { 10 | # say "checking n: $n"; 11 | say $n if $n.is-prime; 12 | } 13 | 14 | # MMDDYYYY 15 | # 01112047 16 | # 01152071 17 | # 01202057 18 | # 01222027 19 | # 01292029 20 | # ... 21 | 22 | # my @werewolf_primes = run($prog, :out).out.slurp.split("\n").sort.grep( .Numeric.is-prime ); 23 | # say @werewolf_primes[0]; 24 | # say @werewolf_primes[1]; 25 | # say @werewolf_primes[2]; 26 | 27 | 28 | -------------------------------------------------------------------------------- /bin/2023mar05/json_comparator_worthington.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # json_comparator_worthington.pl6 08 Jul 2018 4 | 5 | ## Tests two JSON files for equality, parsing them in parallel. 6 | ## A code example by Jonathan Worthington 7 | 8 | use v6; 9 | 10 | use JSON::Tiny; 11 | sub MAIN($file1, $file2) { 12 | my $parsing1 = start from-json( slurp( $file1 )); 13 | my $parsing2 = start from-json( slurp( $file2 )); 14 | 15 | say $parsing1.^name; # Promise 16 | 17 | my ($parsed1, $parsed2) = await $parsing1, $parsing2; 18 | say $parsed1 eqv $parsed2 19 | ?? 'Files contain identical JSON' 20 | !! 'Files contain different JSON'; 21 | } 22 | 23 | # Author: Jonathan Worthington 24 | # Typist: doom@kzsu.stanford.edu 25 | 26 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/Z9-other_stuff_on_raku.org: -------------------------------------------------------------------------------- 1 | * Raku Resources 2 | ** the documentation 3 | *** https://docs.raku.org 4 | 5 | ** SF Perl Raku Study Group 6 | *** https://www.meetup.com/San-Francisco-Perl/ 7 | *** Next one on Sunday, January 16th 8 | 9 | ** mailing lists 10 | *** perl6-users 11 | **** perl6-users-subscribe@perl.org 12 | **** archive: 13 | ***** https://www.nntp.perl.org/group/perl.perl6.users/ 14 | 15 | *** SF Perl mailing list 16 | **** sanfrancisco-pm-request@pm.org 17 | ***** http://sf.pm.org/ 18 | 19 | ** reddit rakulang 20 | *** https://www.reddit.com/r/rakulang/ 21 | ** modules 22 | *** https://modules.raku.org 23 | ** blogs 24 | *** https://planet.raku.org 25 | ** irc raku channel on freenode 26 | *** https://webchat.freenode.net/ 27 | -------------------------------------------------------------------------------- /bin/2021feb07/reduction_over_iteration.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # reduction_over_iteration.pl6 07 Feb 2021 4 | 5 | use v6; 6 | 7 | ## Make errors into warnings 8 | ## CATCH { default { say "CAUGHT: ", .Str; .resume } } 9 | 10 | 11 | my @rabbits = < bugs peter easter >; 12 | my $all ~= @rabbits; ## note: if you've got p5 eyes, ~= seems *really* strange 13 | say "...$all..."; # ...bugs peter easter... 14 | 15 | .say for @rabbits; 16 | # bugs 17 | # peter 18 | # easter 19 | 20 | say .[0] [~] .[1] for @rabbits.rotor(2); 21 | # bugspeter 22 | 23 | say .[0] [~] .[1] for @rabbits.rotor(2, :partial); 24 | # Use of uninitialized value element of type Any in string context. 25 | 26 | 27 | 28 | # === 29 | # Author: doom@kzsu.stanford.edu 30 | 31 | -------------------------------------------------------------------------------- /bin/2022jan02/shitov_rotate_example.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # shitov_rotate_example.raku 02 Jan 2022 4 | 5 | use v6; 6 | 7 | { 8 | my @a = (1, 3, 5, 7, 9, 11, 13, 15); 9 | my $a = [1, 3, 5, 7, 9, 11, 13, 15]; 10 | 11 | # $a.=rotate(3); 12 | $a.push( $a.shift ) for 1..3; 13 | 14 | say $a; # [7 9 11 13 15 1 3 5] 15 | } 16 | 17 | { 18 | 19 | my $a = (1,3); 20 | my $b = [1,3]; 21 | say .WHAT for $a, $b; 22 | # (List) 23 | # (Array) 24 | 25 | } 26 | 27 | { 28 | my $a = [1, 3, 5, 7, 9, 11, 13, 15]; 29 | # [1 3 5 7 9 11 13 15] 30 | 31 | $a .= push( $a.shift ).say for 1..3; 32 | 33 | # [3 5 7 9 11 13 15 1] 34 | # [5 7 9 11 13 15 1 3] 35 | # [7 9 11 13 15 1 3 5] 36 | 37 | } 38 | -------------------------------------------------------------------------------- /lib/Data/Stub.rakumod: -------------------------------------------------------------------------------- 1 | # doom@kzsu.stanford.edu 2 | # 10 Jul 2021 3 | class Data::Stub { 4 | sub whun is export { 5 | return 1; 6 | } 7 | } 8 | 9 | 10 | =begin pod 11 | 12 | =head1 NAME 13 | 14 | Data::Stub - TODO add short description 15 | 16 | =head1 SYNOPSIS 17 | 18 | use Data::Stub; 19 | 20 | # TODO fill in 21 | 22 | 23 | =head1 DESCRIPTION 24 | 25 | =head1 MOTIVATION 26 | 27 | =head1 NOTES 28 | 29 | =head1 AUTHOR 30 | 31 | Joseph Brenner, doomvox@gmail.com 32 | 33 | =head1 COPYRIGHT AND LICENSE 34 | 35 | Copyright (C) 2020 by Joseph Brenner 36 | 37 | Released under "The Artistic License 2.0". 38 | 39 | =end pod 40 | 41 | -------------------------------------------------------------------------------- /bin/2021mar21/parsing_quoted_strings.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # parsing_quoted_strings.raku 21 Mar 2021 4 | 5 | use v6; 6 | 7 | ## Make errors into warnings 8 | CATCH { default { say "CAUGHT: ", .Str; .resume } } 9 | 10 | my $txt = q:to/END_TXT/; 11 | Here we have a "quoted" string. 12 | END_TXT 13 | 14 | { 15 | ## character classes in raku 16 | my $str = "abcxyz"; 17 | $str ~~ m/ ( <-[a]>+ ) /; 18 | say $/; 19 | } 20 | 21 | { 22 | my $qq = chr(2*16+2); # " 23 | say $qq; 24 | my regex simple_q { \" <-["]>* \" }; 25 | 26 | $txt ~~ m//; 27 | say $/; 28 | # 「"quoted"」 29 | # simple_q => 「"quoted"」 30 | 31 | say $/; # 「"quoted"」 32 | say $; # 「"quoted"」 33 | } 34 | -------------------------------------------------------------------------------- /bin/2022jan02/bruce_gray_example_custom_associative.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bruce_gray_example_custom_associative.raku 02 Jan 2022 4 | 5 | use v6; 6 | 7 | class Foo is Associative { 8 | has %.secret_storage; 9 | 10 | ## might work fine without the multi 11 | ## refers to current class: 12 | ## ::?CLASS:D: 13 | ## need this to be able to say :D, force it to be a defined class, an instance of Foo 14 | 15 | multi method ASSIGN-KEY ( ::?CLASS:D: $key, $new_value ) { 16 | %.secret_storage{$key} = $new_value; 17 | } 18 | } 19 | my $f = Foo.new; 20 | $f{'abc!!!'} = 123; 21 | say $f; 22 | ## Foo.new(secret_storage => {"abc!!!" => 123}) 23 | 24 | 25 | 26 | 27 | # === 28 | # Author: doom@kzsu.stanford.edu 29 | 30 | -------------------------------------------------------------------------------- /bin/2024jan21/basics_of_match_object.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # basics_of_match_object.raku 21 Jan 2024 4 | 5 | use v6; 6 | 7 | my $s = 'roses are red'; 8 | my $mo = $s ~~ s/roses/lilacs/; 9 | 10 | dd $mo; 11 | # Match $mo = Match.new(:orig("roses are red"), :from(0), :pos(5)) 12 | 13 | say "$mo"; 14 | # roses 15 | 16 | 17 | { 18 | my $str = ($s ~~ S/roses/lilacs/); 19 | say $str; # True 20 | } 21 | 22 | { 23 | $_ = $s; 24 | my $str = S/roses/lilacs/; 25 | say $str; # lilacs are red 26 | } 27 | 28 | { 29 | $_ = $s; 30 | my $str = .subst( 'roses', 'lilacs' ); 31 | say $str; # lilacs are red 32 | } 33 | 34 | { 35 | $s ~~ s/roses/lilacs/; 36 | my $str = $<>; ## Bill idea... 37 | say $str; # (Any) 38 | } 39 | -------------------------------------------------------------------------------- /bin/2022jan16/crossproduct_metaoperator.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # crossproduct_metaoperator.raku 16 Jan 2022 4 | 5 | use v6; 6 | 7 | my @current_gen = 2, 3, 7, 13; 8 | 9 | my @stuff = 10 | (1..9) X~ @current_gen; 11 | 12 | say @stuff; 13 | 14 | # [12 13 17 113 22 23 27 213 32 33 37 313 42 43 47 413 52 53 57 513 62 63 67 613 72 73 77 713 82 83 87 813 92 93 97 913] 15 | 16 | 17 | my @monsters = ; 18 | 19 | say "monster-" X~ @monsters; 20 | # (monster-blob monster-tingler monster-godzilla) 21 | 22 | my @mfiles = @monsters X~ ".dat"; 23 | say @mfiles; 24 | # [blob.dat tingler.dat godzilla.dat] 25 | 26 | 27 | # hashes abused like sets 28 | my %hash = @array X=> 1; 29 | 30 | ## perl5 31 | # my %hash = map{ $_ => 1 } @array; 32 | -------------------------------------------------------------------------------- /lib/Doomfiles/Parse.rakumod: -------------------------------------------------------------------------------- 1 | # doom@kzsu.stanford.edu 2 | # 28 Mar 2021 3 | 4 | 5 | class Doomfiles::Parse { 6 | 7 | 8 | 9 | 10 | } 11 | 12 | 13 | =begin pod 14 | 15 | =head1 NAME 16 | 17 | Doomfiles::Parse - tools for parsing "doomfiles" 18 | 19 | =head1 SYNOPSIS 20 | 21 | use Doomfiles::Parse; 22 | 23 | # TODO fill in 24 | 25 | 26 | =head1 DESCRIPTION 27 | 28 | =head1 MOTIVATION 29 | 30 | =head1 NOTES 31 | 32 | =head1 AUTHOR 33 | 34 | Joseph Brenner, doomvox@gmail.com 35 | 36 | =head1 COPYRIGHT AND LICENSE 37 | 38 | Copyright (C) 2020 by Joseph Brenner 39 | 40 | Released under "The Artistic License 2.0". 41 | 42 | =end pod 43 | 44 | -------------------------------------------------------------------------------- /bin/2021jun20/junctionism.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # junctionism.raku 20 Jun 2021 4 | 5 | use v6; 6 | 7 | my $a = 3; 8 | 9 | # check if 3 is one of a number of values in one step with "any": 10 | if $a == any( 3, 5, 42 ) { 11 | say "we're in!"; 12 | } 13 | 14 | ## shorthand to create an "any" junction is: "|" 15 | ## Note: bitwise is now +| 16 | if $a == 3|5|42 { 17 | say "we're in!"; 18 | } 19 | 20 | # those are much neater than: 21 | if $a == 3 || $a == 5 || $a == 42 { 22 | say "we're in!"; 23 | } 24 | 25 | 26 | my $silly_junction = ($a == 3) | ($a == 5) | ($a == 42); 27 | say $silly_junction; # any(True, False, False) 28 | say $silly_junction.WHAT; # (Junction) 29 | if $silly_junction { 30 | say "hi there"; # hi there 31 | } 32 | 33 | -------------------------------------------------------------------------------- /bin/2024oct20/visibility_dynamics-iii.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # visibility_dynamics.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | say "1: ", $*RAT-OVERFLOW; # Num 8 | say $*RAT-OVERFLOW.WHICH; 9 | 10 | say "2: "; 11 | check_via_a_sub(); # Num 12 | { 13 | temp $*RAT-OVERFLOW = FatRat; 14 | say $*RAT-OVERFLOW.WHICH; 15 | # my $*RAT-OVERFLOW = FatRat; 16 | 17 | say "3: "; 18 | check_via_a_sub(); ## what does this see? # FatRat! (take that) 19 | 20 | say "4: "; 21 | say $*RAT-OVERFLOW; # FatRat 22 | } 23 | 24 | say "5: ", $*RAT-OVERFLOW; # Num 25 | 26 | 27 | 28 | sub check_via_a_sub { 29 | say $*RAT-OVERFLOW.WHICH; 30 | say "checking via this check_via_a_sub sub"; 31 | say $*RAT-OVERFLOW; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /bin/2024dec08/try_again.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # try_again.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | 8 | { 9 | my $str = 'nothing'; 10 | say ">$str <"; 11 | say ">$str<"; 12 | 13 | ## duplicating what I thought was a repl thing, I see the same behavior in thsi script: 14 | ## 15 | ## Unable to parse quote-words subscript; couldn't find '>' (corresponding '<' was at line 11) 16 | 17 | } 18 | 19 | 20 | { 21 | my $str = 'nothing'; 22 | say ">$str <<"; 23 | say ">$str<<"; 24 | 25 | ## Two angles give you the LTA message I was talking about: 26 | ## Unable to parse expression in double quotes; couldn't find final '"' (corresponding starter was at line 23) 27 | 28 | 29 | say ">>>$str<<<"; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /bin/2023apr16/ue.data: -------------------------------------------------------------------------------- 1 | DEG = 1.500 2 | 2.600D+01 0.000D+00 0.000D+00 0.000D+00 0.000D+00 3 | 2.700D+01 8.720-304 2.369-316 7.556-316 9.410-316 4 | 4.300D+01 1.208D-83 4.156D-96 7.360D-96 6.984D-96 5 | 1.590D+02 8.002D-07 6.555D-19 7.748D-19 7.376D-19 6 | 1.600D+02 1.173D-06 9.669D-19 1.143D-18 1.089D-18 7 | 1.610D+02 1.709D-06 1.417D-18 1.676D-18 1.596D+01 8 | 1.620D+02 2.468D-06 2.058D-18 2.436D-18 2.320D-10 9 | DEG = 18.500 10 | 2.700D+01 2.794-314 0.000D+00 0.000D+00 0.000D+00 11 | 2.800D+01 4.352-285 1.224-297 3.685-297 4.412-297 12 | 8.800D+01 1.371D-02 6.564D-15 7.852D-15 7.275D-15 -------------------------------------------------------------------------------- /bin/2022apr24/cool_object_fields.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # cool_object_fields.raku 24 Apr 2022 4 | 5 | use v6; 6 | 7 | class MyRow { 8 | has Numeric(Cool) $.area is rw; 9 | } 10 | 11 | my $r1 = MyRow.new( area => 6 ); 12 | my $r2 = MyRow.new( area => '6' ); 13 | 14 | say $r2.area; # 6 15 | 16 | $r2.area = 7; 17 | say $r2.area; # 7 18 | 19 | $r2.area = '123'; 20 | say $r2.area; # 123 21 | 22 | say $r2.area.WHAT; # (Int) 23 | 24 | dd $r2; # MyRow $r2 = MyRow.new(area => 123) 25 | 26 | $r1.area = 6.67; 27 | say $r1.area; # 6.67 28 | say $r1.area.WHAT; # (Rat) 29 | 30 | say $r1.area.nude; # (667 100) 31 | 32 | $r1.area = cos(45); 33 | say $r1.area; 34 | say $r1.area.WHAT; # (Num) 35 | 36 | 37 | 38 | 39 | 40 | # === 41 | # Author: doom@kzsu.stanford.edu 42 | 43 | -------------------------------------------------------------------------------- /bin/2024jun30/non_numeric_ranges.txt: -------------------------------------------------------------------------------- 1 | ## capture of a raku repl session, playing quickly with a range of characters 2 | 3 | [0] > say ("a".."e").[3]; 4 | d 5 | [0] > say ("a".."e") 6 | "a".."e" 7 | [0] > say ("a".."e").raku; 8 | WARNING: unhandled Failure detected in DESTROY. If you meant to ignore it, you can mark it as handled by calling .Bool, .so, .not, or .defined methods. The Failure was: 9 | Index out of range. Is: 3, should be in 0..0 10 | in block at line 1 11 | 12 | "a".."e" 13 | [0] > say ("a".."e")[]; 14 | "a".."e" 15 | [0] > say ("a".."e").[]; 16 | "a".."e" 17 | [0] > say ("a".."e").[0..Inf] 18 | (a b c d e) 19 | [0] > say ("a".."e").[*]; 20 | (a b c d e) 21 | [0] > say ("a".."e").list; 22 | (a b c d e) 23 | [0] > say ("a".."e").List; 24 | (a b c d e) 25 | [0] > 26 | -------------------------------------------------------------------------------- /bin/2025dec07/spy_sub_as_method.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # spy_sub_as_method.raku 07 Dec 2025 4 | 5 | use v6; 6 | 7 | ## Groping (unsuccesfully) for a good example of "spy" and the "&." feature 8 | 9 | 10 | my @monsters = < goategon hargon esterk zoma hornbeat chopclown slabbit boneslave >; ## monster-db.com 11 | 12 | 13 | { 14 | @monsters.map({ uc($_) if $_ eq "zoma"; $_ }).sort>>.lc.say; 15 | # (boneslave chopclown esterk goategon hargon hornbeat slabbit zoma) 16 | } 17 | 18 | { 19 | @monsters.map({ uc($_) if $_ eq "zoma"; $_ }).&spy.sort>>.lc.say; 20 | sub spy($_) { say "|| $_ ||"; $_; } 21 | 22 | ## || goategon hargon esterk zoma hornbeat chopclown slabbit boneslave || 23 | ## (boneslave chopclown esterk goategon hargon hornbeat slabbit zoma) 24 | } 25 | -------------------------------------------------------------------------------- /bin/2021apr11/raku_dualvars_via_but.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # raku_dualvars_via_but.raku 07 Apr 2021 4 | 5 | use v6; 6 | 7 | my $n = 3 but 'three'; 8 | 9 | say $n; # three 10 | say "$n"; # three 11 | 12 | say $n + 1; # 4 13 | 14 | say +$n; # three 15 | 16 | my $m = $n++; 17 | 18 | # my $m = [$n++]; ## ... but what did I think the square brackets were for? 19 | 20 | ## But this is an LTA error message: 21 | 22 | # $m = $m--; 23 | # No such method 'pred' for invocant of type 'Array'. Did you mean any 24 | # of these: 'grep', 'ord', 'tree'? 25 | 26 | ## So I was treating an array like a numeric scalar with the "--" operator, 27 | ## and that under the hood tries to call "pred": would be better if the 28 | ## error message used the operator "--" 29 | 30 | say $m; # three 31 | -------------------------------------------------------------------------------- /bin/2023aug06/messing.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # messing.raku 06 Aug 2023 4 | 5 | use v6; 6 | 7 | ## Making some mistakes on purpose to see the error messages 8 | 9 | # { 10 | # my $a = "hey"; 11 | # my $b = "ho"; 12 | # my $c = "$a $b $c"; 13 | # ## Cannot use variable $c in declaration to initialize itself 14 | # } 15 | 16 | 17 | { 18 | my ($a, $b) = "hey", "ho"; 19 | my $c = "yo"; 20 | $c++; 21 | say $c; # yp (perlish, but arguably wrong) 22 | } 23 | 24 | 25 | { 26 | my ($a, $b) = "hey", "ho"; 27 | my Str $c = "yo"; 28 | $c++; 29 | say $c; # yp 30 | 31 | $c = $c + 1; 32 | ## Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏yp' (indicated by ⏏) 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /bin/2023dec03/mark_a_question_match_warning.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # mark_a_question_match_warning.raku 03 Dec 2023 4 | 5 | use v6; 6 | 7 | say so "I used Photoshop" ~~ m:i/ photoshop /; 8 | 9 | say "==="; 10 | 11 | say so "I used Photoshop" ~~ m:i/ photo shop /; # this warns 12 | say so "I used Photoshop" ~~ m:i/ photo shop /; # this *doesn't* warn 13 | 14 | say "==="; 15 | 16 | say so "I used Photoshop" ~~ m:i:s/ photo shop /; 17 | 18 | 19 | say so "I used Photoshop" ~~ m:i/ photo ' ' shop /; 20 | 21 | say so "I used Photoshop" ~~ m:i/ photo \s shop /; 22 | 23 | 24 | 25 | 26 | 27 | # Q: how do you turn off warnings (technically: "worries") you don't want? 28 | # A: we're not sure. 29 | 30 | # A "worry" is a compile-time "warning" 31 | 32 | -------------------------------------------------------------------------------- /bin/2025aug10/slipping_ranges_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # slipping_ranges_etc.raku 10 Aug 2025 4 | 5 | use v6; 6 | 7 | 8 | my @a = 0..50; 9 | say @a[ |(3,5,7, 9 ... 11), |(13..15) ]; 10 | ## (3 5 7 9 11 13 14 15) 11 | 12 | say @a[ |(3,5,7, 9 .. 11), |(13..15) ]; 13 | ## (3 5 7 (9 10 11) 13 14 15) 14 | 15 | say @a[ |(3,5,7, |(9..11) ), |(13..15) ]; 16 | ## (3 5 7 9 10 11 13 14 15) 17 | 18 | say @a[ (3,5,7, 9..11, 13..15).flat ]; 19 | ## (3 5 7 9 10 11 13 14 15) 20 | 21 | ## No need for the hammer this time: 22 | ## say @a[ (3,5,7, 9..11, 13..15).flat(:hammer) ]; ## syntax? 23 | 24 | say "==="; 25 | my $s := 1, 3, 5 ... 13; 26 | say $s[3]; # 7 27 | say $s[2]; # 5 28 | 29 | say $s[3]; # 7 ## Q: what happened to "exhaustion"? There's no .cache here. 30 | 31 | -------------------------------------------------------------------------------- /bin/2023jun04/operator_introspection.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # operator_introspection.raku 04 Jun 2023 4 | 5 | use v6; 6 | 7 | ## https://stackoverflow.com/questions/76309515/how-to-introspect-a-raku-operator 8 | 9 | ## syntax for operator introspection 10 | 11 | say &infix:<->.WHAT; 12 | # (Sub+{is-pure}) 13 | 14 | ## "is-pure": like a pure function. depends on arguments, has no side-effects. 15 | 16 | say &infix:<~>.WHAT; 17 | # (Sub+{is-pure}) 18 | 19 | 20 | say &infix:<~>.^mro; 21 | # ((Sub+{is-pure}) (Sub) (Routine) (Block) (Code) (Any) (Mu)) 22 | 23 | 24 | say &infix:<~>.arity; ## 0 25 | 26 | ## bg example of arity method 27 | # raku -e 'sub foo ( $a, $b ) {...}; say &foo.arity' 28 | # 2 29 | 30 | 31 | say [+](1, 2, 3); # 6 32 | say (1, 2, 3)>>.WHAT; # (List) ??? 33 | -------------------------------------------------------------------------------- /bin/2021feb14/spy_via_ampersand.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # spy_via_ampersand.pl6 September 20, 2020 4 | # February 14, 2021 5 | 6 | use v6; 7 | 8 | my @monsters = 9 | << godzilla blob mothera mechazilla tingler garuda gammera >>; 10 | say "result: ", @monsters.grep({ m/^g/ }).&spy.grep({ m/z/ }).map({ .uc }); 11 | 12 | sub spy { 13 | say "Spying on: ", callframe(1); 14 | dd @_; 15 | return @_; 16 | } 17 | 18 | 19 | say "==="; 20 | # talking about method calls and $_ 21 | say 66.cos; # -0.99964745596635 22 | 23 | $_ = 77; 24 | say .cos; # -0.03097503173121646 25 | 26 | say .map({ .uc }); # (AAA BBB CCC) 27 | say .map( *.uc ); # (AAA BBB CCC) 28 | say .map: *.uc ; # (AAA BBB CCC) 29 | -------------------------------------------------------------------------------- /bin/2021jan24/grammar_calculator_example.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # 2021jan24-grammar_calculator_example.pl6 24 Jan 2021 4 | 5 | use v6; 6 | 7 | # Example from page (under Proto regexes): 8 | # https://docs.raku.org/language/grammars 9 | 10 | grammar Calculator { 11 | token TOP { [ | ] } 12 | rule add { '+' } 13 | rule sub { '-' } 14 | token num { \d+ } 15 | } 16 | 17 | class Calculations { 18 | method TOP ($/) { make $ ?? $.made !! $.made; } 19 | method add ($/) { make [+] $; } 20 | method sub ($/) { make [-] $; } 21 | } 22 | 23 | say Calculator.parse('2 + 3', actions => Calculations).made; 24 | ## 5 25 | 26 | 27 | say Calculator.parse('3 - 7', actions => Calculations).made; 28 | ## -4 29 | 30 | -------------------------------------------------------------------------------- /bin/2021sep12/sum_of_primes_in_odd_positions_is_prime.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # sum_of_primes_in_odd_positions_is_prime.pl6 12 Sep 2021 4 | 5 | # http://rosettacode.org/wiki/Sum_of_primes_in_odd_positions_is_prime#Raku 6 | 7 | use v6; 8 | 9 | my $range = 10000000; 10 | say "range: $range"; 11 | my @odd = grep { ++$ !%% 2 }, grep &is-prime, 2 ..^ $range; 12 | 13 | my @sums = [\+] @odd; 14 | # say @sums.elems; 15 | # say @sums; 16 | 17 | say .fmt('%5d') for grep { .[2].is-prime }, ( (1,3 ... *) Z @odd Z @sums ); 18 | 19 | # 1 2 2 20 | # 3 5 7 21 | # 11 31 89 22 | # 27 103 659 23 | # 35 149 1181 24 | # 67 331 5021 25 | # 91 467 9923 26 | # 95 499 10909 27 | # 99 523 11941 28 | # 119 653 17959 29 | # 143 823 26879 30 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/J2-trial-perl5_inline-solution_0.pl6: -------------------------------------------------------------------------------- 1 | #!/opt/rakudo-star-2018.01/bin/perl6 2 | # 3 | # trial-perl5_inline.pl6 30 Jun 2019 4 | 5 | use Inline::Perl5; 6 | my $p5 = Inline::Perl5.new; 7 | 8 | my $perl5_code = q:to/END/; 9 | sub p5_data { 10 | my @monsters = qw( dalek godzilla blob tingler kong dorisday ); 11 | return @monsters; 12 | } 13 | 14 | p5_data(); 15 | END 16 | 17 | # my @stuff = $p5.run( $perl5_code ); 18 | my @stuff = $p5.run: $perl5_code; 19 | say @stuff; # [5] 20 | 21 | my @thingies = $p5.call('p5_data'); 22 | say @thingies; 23 | # [dalek godzilla blob tingler kong dorisday] 24 | 25 | # Ah, okay-- that works. 26 | ## 27 | ## Note: 28 | ## o defined a sub, then called the sub later 29 | ## o run implies scalar context, call implies list 30 | -------------------------------------------------------------------------------- /md_exp/bin/multidispatch_overlapping_subsets_use_order_dependency-a.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 29 Sep 2021 3 | # multidispatch_overlapping_subsets_use_order_dependency-a.raku 4 | 5 | ## This is a case with two multis imported from different modules, which 6 | ## each use a subset of Str with a list of strings that has an overlap, an 7 | ## ambiguous case which is resolved by order of definition of the multi, 8 | ## and hence the order of the "use" lines. 9 | 10 | use v6; 11 | 12 | use lib $*PROGRAM.parent(2).add("lib"); 13 | 14 | { 15 | say "a: Hero Monster trial run"; 16 | use Speak::Hero; 17 | use Speak::Monster; 18 | speak('godzilla'); ## The hero, godzilla shouts! 19 | } 20 | 21 | 22 | 23 | 24 | 25 | # === 26 | # Author: doom@kzsu.stanford.edu 27 | 28 | -------------------------------------------------------------------------------- /md_exp/bin/multidispatch_overlapping_subsets_use_order_dependency-b.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 29 Sep 2021 3 | # multidispatch_overlapping_subsets_use_order_dependency-b.raku 4 | 5 | ## This is a case with two multis imported from different modules, which 6 | ## each use a subset of Str with a list of strings that has an overlap, an 7 | ## ambiguous case which is resolved by order of definition of the multi, 8 | ## and hence the order of the "use" lines. 9 | 10 | use v6; 11 | 12 | use lib $*PROGRAM.parent(2).add("lib"); 13 | 14 | { 15 | say "a: Monster Hero trial run"; 16 | use Speak::Monster; 17 | use Speak::Hero; 18 | speak('godzilla'); ## The monster, godzilla roars! 19 | } 20 | 21 | 22 | 23 | 24 | # === 25 | # Author: doom@kzsu.stanford.edu 26 | 27 | -------------------------------------------------------------------------------- /bin/2022aug07/rob_using_topic_vs_named_var.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # rob_using_topic_vs_named_var.raku 07 Aug 2022 4 | 5 | use v6; 6 | 7 | say "abc".flip; # cba 8 | say 123.flip; # 321 9 | 10 | say topic("123"); # 444 11 | say named("123"); # 444 12 | 13 | say 123 + 321; # 444 14 | 15 | 16 | sub topic( $c --> Int ) { 17 | $_ = $c; 18 | $_ += .flip; 19 | } 20 | 21 | sub named( $c --> Int ) { 22 | my $d = $c; 23 | # $d += .flip; 24 | $d += $d.flip; 25 | } 26 | 27 | 28 | sub simpler( $c --> Int ) { 29 | # $c += $c.flip; # Cannot assign to a readonly variable or a value 30 | # say $c; 31 | return $c + $c.flip; 32 | } 33 | say simpler( 910 ); # 929 34 | 35 | 36 | for 32 { ## given better than for 37 | say .&topic; # 55 38 | say .&named; # 55 39 | } 40 | -------------------------------------------------------------------------------- /bin/2025feb23/forcing_type_from_list_of_numbers.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # forcing_type_from_list_of_numbers.raku 23 Feb 2025 4 | 5 | use v6; 6 | { 7 | my @n = 1, 2, 3, 4; 8 | say @n; 9 | say @n.WHAT; # (Array) 10 | say @n[2].WHAT; # (Int) 11 | } 12 | 13 | { 14 | my @n = ( 1, 2, 3, 4 ).map({.Rat}); 15 | say @n; 16 | say @n.WHAT; # (Array) 17 | say @n[2].WHAT; # (Rat) 18 | } 19 | 20 | { 21 | my @n = ( 1, 2, 3, 4 )>>.Rat; 22 | say @n; 23 | say @n.WHAT; # (Array) 24 | say @n[2].WHAT; # (Rat) 25 | } 26 | 27 | { 28 | my @n = ( 1, 2, 3, 4 )>>.FatRat; 29 | say @n; 30 | say @n.WHAT; # (Array) 31 | say @n[2].WHAT; # (FatRat) 32 | } 33 | 34 | ## Rob suggests it would be good to have funky brackets that force a numeric type 35 | 36 | -------------------------------------------------------------------------------- /bin/2024mar24/digit_sum.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # digit_sum.raku 24 Mar 2024 4 | 5 | use v6; 6 | 7 | # a component of weekly challenge 261 #1 8 | 9 | my @a = (12, 99, 2); 10 | 11 | # say @a.map({ $_.Str.split }); 12 | 13 | my @dig; 14 | for @a -> $n { 15 | # say $n.Str.split(''); 16 | @dig.push( | $n.split('') ); 17 | } 18 | say @dig; 19 | 20 | ## forgot about comb (again) 21 | ## digits are .Int of course 22 | 23 | for @dig -> $d { 24 | say $d; 25 | } 26 | 27 | 28 | # Rob: 29 | 30 | multi digit-sum( $a -->Int) { 31 | $a.sum 32 | - sum $a.map({ sum .abs.Str.comb>>.Int }; 33 | } 34 | 35 | # Bruce makes the point .Str and .Int here aren't needed: implicit coercion 36 | 37 | ## Bruce: there's a .sign 38 | ## $a.map({ .abs.comb.sum *.sign }).sum 39 | # https://docs.raku.org/routine/sign 40 | -------------------------------------------------------------------------------- /bin/2024mar24/enum_with_an_x.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # enum_with_an_x.raku 24 Mar 2024 4 | 5 | use v6; 6 | 7 | # Daniel Mita mentions using an "x" in an enum as a Raku gotcha 8 | 9 | ## Oh, actually he referred to the upper-case X: 10 | ## I accidentally put 'X' in an enum once, I won't make that mistake again 😂 11 | 12 | ## My naive expectation was that an enum would be lexically scoped: you need a "my" to get that behavior 13 | 14 | { 15 | # say x; 16 | ## Undeclared routine: 17 | } 18 | 19 | { 20 | my $str = "a" x 5; 21 | say $str; # aaaaa 22 | } 23 | 24 | { 25 | my enum xyz ; 26 | my $str = "a" x 5; 27 | say $str; # aaaaa 28 | 29 | say x+0; # 1 30 | } 31 | 32 | { 33 | say x; # x 34 | ## Undeclared routine: 35 | } 36 | 37 | 38 | # enum Bool 39 | -------------------------------------------------------------------------------- /bin/2024nov24/min_max_of_arrays.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # min_max_of_arrays.raku 24 Nov 2024 4 | 5 | use v6; 6 | 7 | my @a = (1, 2, 3); 8 | say @a.min; # 1 9 | say @a.max; # 3 10 | 11 | my @b = (); 12 | say @b.min; # Inf 13 | say @b.max; # -Inf 14 | 15 | my @c = ('a', 'b', 'c'); 16 | say @c.min; # a 17 | say @c.max; # c 18 | 19 | say "---"; 20 | { 21 | my $max; 22 | ## warns first time: Use of uninitialized value of type Any in numeric context 23 | for @a -> $item { 24 | $max = $item if $item > $max; 25 | } 26 | say $max; # 3 27 | } 28 | 29 | say "---"; 30 | { 31 | my $max; 32 | ## warns first time: Use of uninitialized value of type Any in numeric context 33 | for @b -> $item { 34 | $max = $item if $item > $max; 35 | } 36 | say $max; # (Any) 37 | } 38 | -------------------------------------------------------------------------------- /bin/2022may08/are.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # are.raku 08 May 2022 4 | 5 | use v6; 6 | 7 | my @a = 1,3.2,'a',2e2; #[1 3.2 a 200] 8 | say @a.are; #(Cool) 9 | 10 | my @b = 1,3.2,2e2; #[1 3.2 200] 11 | say @b.are; #(Real) 12 | 13 | my @c = <<1>>, 1, 3; #[1 1 3] 14 | say @c[0].^name; #IntStr 15 | say @c.are; #(Int) 16 | 17 | my @d = ; #[a b c] 18 | say @d.are; #(Str) 19 | 20 | @d.push: <<1>>; #[a b c 1] 21 | say @d[3].^name; #IntStr 22 | say @d.are; #(Str) 23 | 24 | my $d = "2022-01-03".Date; #2022-01-03 25 | say @d.push: $d; #[a b c 1 2022-01-03] 26 | say @d.are; #(Any) 27 | 28 | my @e = $d xx 4; #[2022-01-03 2022-01-03 2022-01-03 2022-01-03] 29 | say @e.are; #(Date) 30 | 31 | 32 | say "==="; 33 | my @z = ( Mu.new, Any.new ); 34 | say @z.are; 35 | # (Mu) 36 | 37 | -------------------------------------------------------------------------------- /bin/2023apr16/unixstackexchange_fortran_d_to_scientific_e_and_filter.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # 16 Apr 2023 4 | 5 | use v6; 6 | 7 | ## william michaels code reformatted slightly 8 | my @a; 9 | 10 | for lines.join("\n").split(/ \n /) { 11 | @a.push: 12 | %(.split("\n").[0].words.[2] => .split("\n")[1..*].map( 13 | *.words[0,4])>>.map(*.subst( / (\d+) (<[+-]>) /, 14 | {$0 ~ "e" ~ $1 } 15 | ).subst(/D/, "e") )>>.Num) 16 | }; 17 | 18 | .raku.put for @a; 19 | 20 | # ${"1.500" => $($(26e0, 0e0), $(27e0, 9.41e-316), $(43e0, 6.984e-96), $(159e0, 7.376e-19), $(160e0, 1.089e-18), $(161e0, 15.96e0), $(162e0, 2.32e-10))} 21 | # ${"18.500" => $($(27e0, 0e0), $(28e0, 4.412e-297), $(88e0, 7.275e-15))} 22 | -------------------------------------------------------------------------------- /bin/2024apr07/subset_columns.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # subset_columns.raku 07 Apr 2024 4 | 5 | use v6; 6 | 7 | my @required = ; 8 | my @additional = ; 9 | my @fields = | @required, | @additional; 10 | 11 | # say @fields; 12 | 13 | my $file = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024apr07/dat/data.csv"; 14 | 15 | my ($header,@l) = $file.IO.lines; 16 | # dd @l; 17 | .say for @l; 18 | 19 | my @indicies; 20 | for $header.split( /\s+/ ).keys -> $i { 21 | say $i; 22 | my $colname = $header.[$i]; 23 | say $colname; 24 | 25 | my $s = Set.new( @fields ); 26 | dd $s; # Set $s = Set.new("alt","ref","a4","a1","pos","chrom") 27 | 28 | if ($colname (elem) $s ) { 29 | say $i; 30 | 31 | } 32 | 33 | 34 | 35 | } 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /bin/2023jan01/dpchrist_p5_threaded_code.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 2023/01/01 22:09:58 3 | 4 | =head1 NAME 5 | 6 | dpchrist_p5_threaded_code.pl 7 | 8 | =head1 SYNOPSIS 9 | 10 | 11 | =head1 DESCRIPTION 12 | 13 | Stub documentation for dpchrist_p5_threaded_code.pl, 14 | created by template.el. 15 | 16 | It looks like the author of this script was negligent 17 | enough to leave the stub unedited. 18 | 19 | =cut 20 | 21 | use 5.10.0; 22 | use warnings; 23 | use strict; 24 | $|=1; 25 | use Data::Dumper; 26 | 27 | ## dpchrist likes $_ because it's "sharedness" is preserved in threaded code. 28 | 29 | use threads::shared; 30 | my $thing :shared; 31 | my $thang; 32 | 33 | doingstuff( $thing ); 34 | 35 | sub doingstuff { 36 | local $_ = shift; 37 | 38 | } 39 | 40 | 41 | 42 | doingstuff( $thang ); 43 | 44 | -------------------------------------------------------------------------------- /bin/2025jul27/matrix_add_on_two_vectors.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # matrix_add_on_two_vectors.raku 26 Jul 2025 4 | 5 | use v6; 6 | 7 | ## See: 8 | ## Raku Next Steps: Hypersonic 9 | ## https://www.youtube.com/watch?v=_OMsWYLQLqU 10 | 11 | { 12 | ## increment vector of ages 13 | my @a = 8, 10, 12, 14; 14 | # create a vector of 1s of same length 15 | my @b = 1 xx +@a; 16 | # matrix addition, increment each element 17 | @a = @a >>+<< @b; 18 | 19 | say @a; # [9 11 13 15] 20 | } 21 | 22 | { 23 | my @a = 8, 10, 12, 14; 24 | my @b = 1 xx +@a; 25 | say @b; # [1 1 1 1] 26 | 27 | my @c = 1 xx @a.elems; 28 | say @c; # [1 1 1 1] 29 | } 30 | 31 | { 32 | # also, there's other ways of doing this one.. 33 | my @a = 8, 10, 12, 14; 34 | @a>>++; 35 | say @a; # [9 11 13 15] 36 | } 37 | -------------------------------------------------------------------------------- /bin/2021apr18/ignoremark.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # ignoremark.raku 18 Apr 2021 4 | 5 | use v6; 6 | 7 | say so 'a' ~~ rx/ä/; # OUTPUT: «False» 8 | say so 'a' ~~ rx:ignoremark /ä/; # OUTPUT: «True» 9 | say so 'ỡ' ~~ rx:ignoremark /o/; # OUTPUT: «True> 10 | 11 | say so 'U' ~~ rx:ignoremark /Ü/; 12 | # True 13 | say so 'u' ~~ rx:ignoremark /Ü/; 14 | # False 15 | say so 'u' ~~ rx:ignoremark :i /Ü/; 16 | # True 17 | say so 'aU' ~~ rx:ignoremark /äÜ/; 18 | # True 19 | 20 | 21 | say "1:\t", $/ if "בראשית" ~~ m/ בְּרֵאשִׁית /; 22 | say "2:\t", $/ if "בראשית" ~~ m:ignoremark/ בְּרֵאשִׁית /; #OUTPUT: 「בראשית」 23 | say "3:\t", $/ if "בְּרֵאשִׁית" ~~ m/ בראשית /; 24 | say "4:\t", $/ if "בְּרֵאשִׁית" ~~ m:ignoremark/ בראשית /; #OUTPUT: 「בְּרֵאשִׁית」 25 | # 2: 「בראשית」 26 | # 4: 「בְּרֵאשִׁית」 27 | 28 | 29 | -------------------------------------------------------------------------------- /bin/2025sep07/redoing_bill2.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # redoing_bill2.raku 07 Sep 2025 4 | 5 | use v6; 6 | 7 | { 8 | my @i = 0, 1, 2, 3, 4, 5, 6; # inane array that converts the index into itself. 9 | 10 | # for ( 0..1; 3...1; 3..6 ).flat -> $i { 11 | for ( flat( 0..1; 3...1; 3..6 ) ) -> $i { 12 | print @i[ $i ], "\t"; 13 | } 14 | print "\n"; 15 | ## 0 1 3 2 1 3 4 5 6 16 | 17 | say @i[ ( 0..1; 3...1; 3..6 ).flat ]; 18 | # (0 1 3 2 1 3 4 5 6) 19 | 20 | say "---"; 21 | ## suggestion to play with slip operator, tends to convert into counts 22 | for | (0..1; 3...1; 3..6) -> $i { 23 | say "i: ", $i; 24 | print @i[ $i ], "\n"; 25 | } 26 | print "\n"; 27 | 28 | # i: 0..1 29 | # 2 30 | # i: (3 2 1) 31 | # 3 32 | # i: 3..6 33 | # 4 34 | 35 | } 36 | -------------------------------------------------------------------------------- /bin/2024oct20/array_typology.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # array_typology.raku 20 Oct 2024 4 | 5 | use v6; 6 | 7 | 8 | 9 | my Int @n = 1, 2, 3; 10 | 11 | say @n; # [1 2 3] 12 | 13 | ## @n[3] = 'a'; 14 | 15 | ## # Type check failed for an element of @n; expected Int but got Str ("a") 16 | ## # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024oct20/array_typology.raku line 13 17 | 18 | 19 | @n[3] = 4; 20 | say @n; # [1 2 3 4] 21 | 22 | my $c = 'a'; 23 | 24 | @n[3] := $c; 25 | 26 | 27 | # Cannot resolve caller BIND-POS(Array[Int]:D: Int:D, Str:D); none of these signatures matches: 28 | # (Array:D: uint $pos, Int \bindval, *%_) 29 | # (Array:D: Int:D $pos, Int \bindval, *%_) 30 | # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024oct20/array_typology.raku line 24 31 | 32 | 33 | -------------------------------------------------------------------------------- /bin/2024oct20/rat_docs.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # rat_docs.raku 20 Oct 2024 4 | 5 | use v6; 6 | 7 | # https://docs.raku.org/language/numerics#Rat 8 | 9 | my $a = 1 / (2⁶⁴ - 1); 10 | say $a; # 0.000000000000000000054 11 | say $a.^name; # Rat 12 | say $a.nude; # (1 18446744073709551615) 13 | 14 | my $b = 1 / 2⁶⁴; 15 | say $b; # 5.421010862427522e-20 16 | say $b.^name; # Num 17 | 18 | my $c = Rat.new(1, 2⁶⁴); ## Why not an error? 19 | say $c; # 0.000000000000000000054 20 | say $c.^name; # Rat ## This form is a Rat? 21 | say $c.nude; # (1 18446744073709551616) ## But this is too big for Rat? 22 | say $c.Num; # 5.421010862427522e-20 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /bin/boolean_conversion_operator.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # boolean_conversion_operator.pl6 13 Dec 2020 4 | 5 | use v6; 6 | 7 | my $flag = True; 8 | say $flag; # True 9 | 10 | say !$flag; # False 11 | say !!$flag; # True 12 | 13 | my $flagoid = ""; 14 | say $flagoid.Bool; # False 15 | 16 | say !!$flagoid; # False 17 | 18 | my $new_bool = !!$flagoid; 19 | say $new_bool; # False 20 | 21 | say $new_bool.WHAT; # (Bool) 22 | 23 | 24 | my $new_bool2 = ?$flagoid; 25 | say $new_bool2; # False 26 | say $new_bool2.WHAT; # (Bool) 27 | 28 | 29 | my $new_bool3 = ? $flagoid; 30 | say $new_bool3.WHAT; # (Bool) 31 | 32 | ## question mark allows following space 33 | ## double bang doesn't 34 | 35 | ## double bangs can be confused with ternaries? 36 | my $thing = $flag ?? "hm" !! "ho"; 37 | say $thing; # hm 38 | 39 | -------------------------------------------------------------------------------- /bin/DeepMap/hash_gyrations.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # hash_gyrations.raku 04 Feb 2025 4 | 5 | use v6; 6 | 7 | my %threat = 8 | ( godzilla => 8, mothera => 6, rhodan => 5, tingler => 3, wolfman => 3, dracula => 4, horta => IterationEnd, blob => 3 ); 9 | 10 | say "yalp!"; 11 | 12 | say %threat; 13 | say %threat.keys; 14 | say %threat.values; 15 | 16 | { # the way it's done in raku core, in the deepmap code 17 | my %new_threat = Hash.new.STORE: %threat.keys, %threat.values, :INITIALIZE; 18 | say %new_threat; 19 | 20 | } 21 | 22 | 23 | { # obvious hash copy, key at a time 24 | my %new; 25 | for %threat.keys -> $k { 26 | %new{ $k } = %threat{ $k }; 27 | } 28 | say %new; 29 | } 30 | 31 | 32 | 33 | { # 34 | my %new; 35 | %new{ $_ } = %threat{ $_ } for %threat.keys; 36 | say %new; 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/H2-bruce_gray_io_lines_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bruce_gray_io_lines_etc.raku 15 Aug 2021 4 | 5 | ## fixing some small bugs bugs in Bruce Gray's slides 6 | ## (lightning talk: "can't be this easy", find link) 7 | 8 | my $file = "/home/doom/tmp/monsters.txt"; 9 | ## contains: 10 | # godzilla 11 | # mothera 12 | # gammera 13 | # wolfman 14 | # kong 15 | # END 16 | # gillman 17 | # tingler 18 | # zuckerberg 19 | 20 | for $file.IO.lines.grep({ ! /^END/ or last }) { 21 | .say if /^k/; 22 | } # kong 23 | 24 | say "==="; 25 | .say for $file.IO.lines.grep({ last if /^END/; True }).grep(/^g/); 26 | # godzilla 27 | # ghidora 28 | 29 | say "==="; 30 | for $file.IO.lines.grep({ !/^END/ or last }) { 31 | .say if /^g/; 32 | } 33 | # godzilla 34 | # ghidora 35 | -------------------------------------------------------------------------------- /bin/2022may08/item.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # item.raku 08 May 2022 4 | 5 | use v6; 6 | 7 | ## https://docs.raku.org/routine/item 8 | 9 | # Forces given object to be evaluated in item context and returns the value of it. 10 | 11 | say [1,2,3]; # [1 2 3] 12 | say item([1,2,3]).raku; # $[1, 2, 3] 13 | 14 | say item( %( apple => 10 ) ).raku; # ${:apple(10)} 15 | say item("abc").raku; # "abc" 16 | 17 | # You can also use $ as item contextualizer. 18 | 19 | say $[1,2,3].raku; # $[1, 2, 3] 20 | say $("abc").raku; # "abc" 21 | 22 | 23 | # https://docs.raku.org/type/Any#index-entry-$_(item_contextualizer) 24 | 25 | # Since Raku intentionally confuses items and single-element lists, 26 | # most methods in Any are also present on class List, and coerce to 27 | # List or a list-like type. 28 | 29 | 30 | -------------------------------------------------------------------------------- /bin/2024aug25/pi_mah_e.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # pi_mah_e.raku 25 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | say π; # 3.141592653589793 9 | 10 | say 𝑒; # 2.718281828459045 11 | 12 | say (𝑒..π).WHAT; 13 | 14 | say (𝑒..π)[2]; # Nil 15 | 16 | if ( 2.8 ~~ (𝑒..π) ) { 17 | say "a hit"; # a hit 18 | } 19 | 20 | for (𝑒..π) -> $n { 21 | say "n: $n"; 22 | } 23 | # n: 2.718281828459045 24 | 25 | 26 | for 𝑒..π -> $n { 27 | say "n: $n"; 28 | } 29 | # n: 2.718281828459045 30 | 31 | say (𝑒..π); 32 | # 2.718281828459045e0..3.141592653589793e0 33 | 34 | say (𝑒..π).map({ say $_ }); # (True) 35 | 36 | say (𝑒..π)>>.map({ say $_ }); # ((True)) 37 | 38 | say (𝑒..π)[0]; # 2.718281828459045 39 | say (𝑒..π)[1]; # Nil 40 | 41 | say (𝑒..π)[*]; # (2.718281828459045) 42 | 43 | say (𝑒..2*π)[1]; # 3.718281828459045 44 | say (𝑒..2*π)[2]; # 4.718281828459045 45 | -------------------------------------------------------------------------------- /bin/2021mar28/first_method_on_arrays.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # first_method_on_arrays.raku 28 Mar 2021 4 | 5 | use v6; 6 | 7 | say "==="; 8 | #Liz IRC 9 | 10 | { 11 | my @a = 3,7,6,12,9,6,6,6; 12 | say @a.first(6, :k); 13 | # 2 14 | 15 | # 0 1 2 3 4 5 6 7 16 | my @a = 3,7,6,12,9,6,6,6; 17 | say @a.first(6, :k, :end); # for the record: from the other end 18 | # 7 19 | 20 | # my @a = ; say @a.elems; say @a.first("E", :k) 21 | # > my @a = ; say @a.elems; say @a.first("E", :k) 22 | # 8 23 | # 7 24 | # > my @a = ; say @a.elems; say @a.first("E", :k, :end) 25 | # 8 26 | # 7 27 | 28 | # my @a = ; say @a.elems; say @a.first("E", :k) 29 | # 9 30 | # 3 31 | # > my @a = ; say @a.elems; say @a.first("E", :k, :end) 32 | 33 | } 34 | 35 | exit; 36 | 37 | -------------------------------------------------------------------------------- /bin/2021jan31/rotate.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # rotate.pl6 31 Jan 2021 4 | 5 | use v6; 6 | 7 | ## https://docs.raku.org/routine/rotate 8 | #### This is a case where the sections of the docs were generated in 9 | #### a poor order, leading with "Supply" rather than "Lists" 10 | 11 | # Using it with Supply: 12 | # available since 2020.06 (but I'm still on 2020.05): 13 | 14 | # my $supply = Supply.from-list( ).rotate( 2 ); 15 | # $supply.tap( &say ); # OUTPUT: «c␤d␤e␤a␤b␤» 16 | 17 | # Running on 2020.05: 18 | # No such method 'rotate' for invocant of type 'Supply' 19 | 20 | # Using rotate with lists: 21 | 22 | # Returns a Seq with the list elements rotated to the left when 23 | # $n is positive or to the right otherwise. 24 | 25 | # Examples: 26 | 27 | say .rotate(2); # OUTPUT: (c d e a b) 28 | say .rotate(-1); # OUTPUT: (e a b c d) 29 | -------------------------------------------------------------------------------- /bin/2021sep26/multi_dispatch_int_collision.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # g 3 | # multi_dispatch_int_collision.raku 24 Sep 2021 4 | 5 | use v6; 6 | 7 | ## Basic (inane?) demo of the "Ambiguous call" error 8 | 9 | multi sub speak (Int $i) { 10 | say "FIRST PLACE: The Int is $i"; 11 | } 12 | 13 | # multi sub speak (Int $i) { 14 | multi sub speak (Int $i) is default { 15 | say "SECOND PLACE: The Int is $i"; 16 | } 17 | 18 | speak(3); 19 | 20 | # OUTPUT: 21 | # 22 | # Without "is default": 23 | # Ambiguous call to 'speak(Int)'; these signatures all match: 24 | # (Int $i) 25 | # (Int $i) 26 | 27 | 28 | # With "is default": 29 | # SECOND PLACE: The Int is 3 30 | # (And the first version will never be called.) 31 | 32 | 33 | # === 34 | # Author: doom@kzsu.stanford.edu 35 | 36 | 37 | -------------------------------------------------------------------------------- /bin/2024dec08/bruce_gray_monkey_augment_str_upgraderat_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # bruce_gray_monkey_augment_str_upgraderat_etc.raku 08 Dec 2024 4 | 5 | use v6; 6 | 7 | 8 | # raku -e 'use MONKEY; augment class Str { method UPGRADE-RAT (Int $numer, Int $denom) { return "$numer/$denom. Bwahaha!"} }; $*RAT-OVERFLOW = "abc"; my $a = (1/(2**63));say $a/2; $*RAT-OVERFLOW = FatRat.new(1,2); say ($a/2).WHAT;' 9 | # 1/18446744073709551616. Bwahaha! 10 | # (FatRat) 11 | 12 | use MONKEY; 13 | augment class Str { 14 | method UPGRADE-RAT (Int $numer, Int $denom) { 15 | return "$numer/$denom. Bwahaha!" 16 | } 17 | }; 18 | 19 | $*RAT-OVERFLOW = "abc"; ## a string of *type* Str; 20 | my $a = (1/(2**63)); 21 | say $a/2; 22 | $*RAT-OVERFLOW = FatRat.new(1,2); ## An object of type FatRat. 23 | say ($a/2).WHAT; 24 | 25 | 26 | # 1/18446744073709551616. Bwahaha! 27 | # (FatRat) 28 | -------------------------------------------------------------------------------- /bin/2021aug29/lca_so_3.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # lca_so_3.raku 29 Aug 2021 4 | 5 | use v6; 6 | 7 | =begin pod 8 | 9 | A 10 | | 11 | ----- 12 | | | 13 | B C 14 | | 15 | D 16 | | 17 | ----- 18 | | | 19 | E F 20 | | 21 | G 22 | 23 | =end pod 24 | 25 | { 26 | class A {}; 27 | class B is A {}; 28 | class C is A {}; 29 | class D is B {}; 30 | class E is D {}; 31 | class F is D {}; 32 | class G is F {}; 33 | 34 | # bruce gray solution: 35 | sub LCA( Mu:U $a, Mu:U $b --> Mu:U ) { 36 | ($a, |$a.^parents).first: * === ($b, |$b.^parents).any; 37 | } 38 | 39 | } 40 | 41 | say LCA(F, G); # (F) 42 | say LCA(E, F); # (D) 43 | say LCA(E, G); # (D) 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/Z8-videos_on_raku.org: -------------------------------------------------------------------------------- 1 | * Raku Videos 2 | ** Leon Timmermans, "Raku syntax I miss in other languages', Jun 8, 2021 3 | *** https://www.youtube.com/watch?v=elalwvfmYgk 4 | *** Hyperoperators, Junctions, etc 5 | 6 | ** Elizabeth Mattjsen - "Raku - Sets without Borders", Jul 17, 2021 7 | *** https://www.youtube.com/watch?v=ymyFchbu_GQ 8 | *** set operators Just Work with arrays, hashes, etc 9 | 10 | ** Jonathan Worthington on CAP ("Concurrency, Asynchrony, Parallelism") 11 | *** "Concurrency, Parallelism and Asynchrony: Perl 6 plotting and prototyping", Sep 10, 2013 12 | **** https://www.youtube.com/watch?v=xg8tAv35YFg 13 | *** "Parallelism, Concurrency, and Asynchrony in Perl 6", Aug 27, 2015 14 | **** https://www.youtube.com/watch?v=JpqnNCx7wVY 15 | 16 | ** Larry Wall, Keynote: Erlang & Elixir Factory San Francisco, Mar 24, 2017 17 | *** https://www.youtube.com/watch?v=SpH9BTMZKXc 18 | 19 | 20 | -------------------------------------------------------------------------------- /bin/2022aug21/02-twiddle_vars.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # 02-twiddle_vars.raku 21 Aug 2022 4 | 5 | use v6; 6 | 7 | { 8 | # Note, I thought Márton Polgár said this didn't work in Raku 9 | my ($a, $b) = (3, 7); 10 | say "a: $a, b: $b"; # a: 3, b: 7 11 | ($b, $a) = ($a, $b); 12 | say "a: $a, b: $b"; # a: 7, b: 3 13 | } 14 | 15 | { 16 | say "==="; 17 | my ($a, $b) = (3, 7); 18 | say "a: $a, b: $b"; # a: 3, b: 7 19 | ($b, $a) = $a, $b; 20 | 21 | say "a: $a, b: $b"; # a: 7, b: 3 22 | } 23 | 24 | { 25 | # funny: no change at all 26 | say "==="; 27 | my ($a, $b) = (3, 7); 28 | say "a: $a, b: $b"; # a: 3, b: 7 29 | $b, $a = $a, $b; 30 | 31 | say "a: $a, b: $b"; # a: 3, b: 7 32 | 33 | # WARNINGS for /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022aug21/02-twiddle_vars.raku: 34 | # Useless use of $b in sink context (lines 29, 29) 35 | 36 | } 37 | -------------------------------------------------------------------------------- /bin/2022feb27/issue_4805_explorations.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # issue_4805_explorations.raku 01 Mar 2022 4 | 5 | use v6; 6 | 7 | 8 | { 9 | my $a1 = 1, 2, 3; # line 9 10 | # Useless use of constant integer 3 in sink context (lines 9, 9) 11 | # Useless use of constant integer 2 in sink context (lines 9, 9) 12 | my $a2 = {a=>1}, {b=>2}, {c=>3}; 13 | # No warnings 14 | say $a1; # 1 the first item, "1", not the list "1, 2, 3" 15 | say $a2; # {a => 1} again, just the first item 16 | 17 | my $a3 = ( {a=>1}, {b=>2}, {c=>3} ); 18 | say $a3; ## ({a => 1} {b => 2} {c => 3}) a list of pairs 19 | say $a3.WHAT; ## (List) 20 | 21 | # Note: you sometimes hear that "commas create a sequence", but here 22 | # (1) You only get the first item in the comma-separated series 23 | # (2) You see different behavior with complex items: no compiler warning 24 | } 25 | -------------------------------------------------------------------------------- /bin/2024jan21/bruce_gray_wants_hashes_that_repel_changes_but_allow_dupes.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 21 Jan 2024 3 | # 4 | # /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024jan21/bruce_gray_wants_hashes_that_repel_changes_but_allow_dupes.raku 5 | 6 | use v6; 7 | 8 | ## General purpose hash to keep track of stuff, duplication expected, but need to verify that 9 | ## if we assign a value for a key again, we want it to accept it if it's a dupe, but object otherwise. 10 | 11 | { 12 | my %h; 13 | %h = 42; 14 | # ... 15 | my ($k, $v) = "a", 43; 16 | die if %h{$k}:exists and %h{$k} != $v; ## better if this was automated 17 | %h{$k} = $v; 18 | 19 | # Died 20 | # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2024jan21/bruce_gray.raku line 11 21 | say %h; # {a => 43} 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /bin/2024jun30/laziness2.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # laziness2.raku 30 Jun 2024 4 | 5 | use v6; 6 | 7 | 8 | sub something { 9 | 10 | # my @a = (1..100000); 11 | # say @a.WHAT; # (Array) 12 | 13 | my $a = (1..100000); 14 | say $a.WHAT; # (Range) 15 | } 16 | 17 | ## Yesterday I thought I saw a big speed difference on $a vs @a: 18 | ## with a value of 1000, it's 0.7s, if this were @a it'd be 1.3m 19 | 20 | # with $a, 21 | # with limit 1000: 22 | # real 0m0.402s 23 | # with limit 100000: 24 | # real 0m0.372s 25 | # with @a 26 | # with limit 1000: 27 | # real 0m0.538s 28 | # with limit 100000: 29 | # real 0m59.612s 30 | 31 | for 1..1000 { 32 | something(); 33 | } 34 | 35 | 36 | ## Theory: yeserday I had a big firefox instance running, which was 37 | ## probably burning a lot of memory. 38 | 39 | ## This morning I only hit the memory ceiling with bigger arrays. 40 | -------------------------------------------------------------------------------- /bin/2021jun20/function_composition_op.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # function_composition_op.raku 20 Jun 2021 4 | 5 | use v6; 6 | 7 | sub f($p){ print 'f: '; $p / 3 } 8 | sub g($p){ print 'g: '; $p * 7 } 9 | 10 | my &composed = &f ∘ &g; 11 | say composed 2; 12 | # g: f: 4.666667 13 | say f(g(2)); 14 | # g: f: 4.666667 15 | say f g 2; 16 | # g: f: 4.666667 17 | say "A: ---"; 18 | say g(2); # g: 14 19 | say "I am about to call f(2)!"; 20 | my $ret = f(2); 21 | say "XXX"; 22 | # f: XXX 23 | say "ZZZ"; # ZZZ 24 | say "ret: ", $ret; # f: ret: 0.666667 25 | say $ret.WHAT; # (Rat) 26 | say $ret.nude; # (2 3) 27 | say "==="; 28 | say 2.&g; 29 | say 3.&g; 30 | say "B: ---"; 31 | 32 | # equivalent to: 33 | say 2.&g.&f; 34 | say "C: ---"; 35 | # g 36 | # f 37 | # 2 38 | # --- 39 | # or to: 40 | say f g 2; 41 | say &composed.arity; # # 1 42 | say &composed.count; # # 1 43 | say &composed.of; # # Mu 44 | -------------------------------------------------------------------------------- /bin/2021oct24/given_when_vs_passing_to_block.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # given_when_vs_passing_to_block.raku 24 Oct 2021 4 | 5 | use v6; 6 | 7 | ## Example in the docs: 8 | 9 | # The given statement is often used alone: 10 | 11 | given 42 { .say; .Numeric; } # 42 12 | 13 | # This is a lot more understandable than: 14 | { .say; 15 | .Numeric; 16 | }(42); # 42 17 | 18 | 19 | sub stuffy($_){ 20 | .say; 21 | .Numeric; 22 | }; 23 | 24 | say stuffy(42); # 42 25 | 26 | { .say; .Numeric; }(42); 27 | { say "$a + $b is {$a+$b}" }(|$_) 28 | 29 | sub mah_stuff { 30 | say "$^a + $^b is {$a+$b}" ; 31 | } 32 | mah_stuff( 42, 23 ); # 42 + 23 is 65 33 | 34 | 35 | sub moes_stuff( $a, $b ) { 36 | say "$a + $b is {$a+$b}" ; 37 | } 38 | moes_stuff( 42, 23 ); # 42 + 23 is 65 39 | 40 | # given !$_ { say $a, $b }; 41 | 42 | 43 | 44 | 45 | # === 46 | # Author: doom@kzsu.stanford.edu 47 | 48 | -------------------------------------------------------------------------------- /bin/2022sep25/arrays_with_sigils_and_without.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # arrays_with_sigils_and_without.raku 25 Sep 2022 4 | 5 | use v6; 6 | 7 | ## Bruce gray: 8 | 9 | { 10 | my @a = 1,2,3; 11 | my @b = ; 12 | (@a, @b) .= reverse; 13 | .say for @a, @b; 14 | # (\Array_94107183402072 = [[] Array_94107183402072]) 15 | } 16 | 17 | # Rob suggests $@ but... 18 | # { 19 | # ($@a, $@b) .= reverse; 20 | # .say for @a, @b; 21 | 22 | # # Cannot assign to a readonly variable or a value 23 | # # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022sep25/arrays_with_sigils_and_without.raku line 18 24 | 25 | # } 26 | 27 | 28 | { 29 | ## Swapping with scalars is easier 30 | my $a = (1,2,3); # but note the need for parens now. 31 | my $b = ; 32 | ($a, $b) .= reverse; 33 | .say for $a, $b; 34 | 35 | # (a b c) 36 | # (1 2 3) 37 | } 38 | -------------------------------------------------------------------------------- /bin/2021aug15/bruce_gray_io_lines_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bruce_gray_io_lines_etc.raku 15 Aug 2021 4 | 5 | ## fixing some small bugs bugs in bruce grey's slides 6 | ## (lightning talk: "can't be this easy", find link) 7 | 8 | use v6; 9 | 10 | my $file = "/home/doom/tmp/monsters.txt"; 11 | ## contains: 12 | # godzilla 13 | # ghidora 14 | # mothera 15 | # gammera 16 | # frankenstein 17 | # wolfman 18 | # kong 19 | # END 20 | # gillman 21 | # tingler 22 | # blob 23 | # zuckerberg 24 | 25 | for $file.IO.lines.grep({ ! /^END/ or last }) { 26 | .say if /^k/; 27 | } # kong 28 | 29 | say "==="; 30 | .say for $file.IO.lines.grep({ last if /^END/; True }).grep(/^g/); 31 | # godzilla 32 | # ghidora 33 | # gammera 34 | 35 | 36 | say "==="; 37 | for $file.IO.lines.grep({ !/^END/ or last }) { 38 | .say if /^g/; 39 | } 40 | # godzilla 41 | # ghidora 42 | # gammera 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /bin/2024mar10/toddandmargo_sort.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # toddandmargo_sort.raku 10 Mar 2024 4 | 5 | use v6; 6 | 7 | ## strings with text prefix and numeric suffix, where the numeric is sorted numerically 8 | ## most likely: sort on the text prefix, then sort in numeric order within prefix 9 | 10 | ## Lizmat's solution: 11 | say .sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List); 12 | # (afoo2 afoo12) 13 | 14 | say "==="; 15 | { 16 | my @list = ; 17 | @list .= sort: +*.match: / \d+ /; 18 | say @list; # [abc0 abc3 abc123] 19 | 20 | @list = ; 21 | @list .= sort: +*.match: / \d+ /; 22 | say @list; # [abc0 blob0 abc3 blob3 abc123 blob123] 23 | } 24 | 25 | say "==="; 26 | { 27 | my @list = ; 28 | @list .= sort({ +$_.match( / \d+ / ) }); 29 | say @list; # [abc0 abc3 abc123] 30 | } 31 | -------------------------------------------------------------------------------- /notes/talks/data_math/C-aside_hash_as_scalar.rectpara: -------------------------------------------------------------------------------- 1 | 2 | Pop quiz: what does this line actually do? 3 | 4 | %net = %gross - %costs; 5 | 6 | Subtraction of hashes puts them in scalar context. 7 | That *used* to give you a "bucket report": 8 | 9 | a numeric ratio in string form reflecting 10 | internal behavior you don't care about. 11 | 12 | BUT ever since perl 5.25: it's a count of keys-- 13 | something you might actually care about. 14 | 15 | See: https://perldoc.perl.org/perldata 16 | 17 | 18 | This doesn't help us much, though. 19 | 20 | 3 - 3 = 0 21 | 22 | Assigning that to a hash generates a warning: 23 | 24 | "Odd number of elements in hash assignment" 25 | 26 | say scalar %gross; # 3 27 | say scalar %costs; # 3 28 | say Dumper( \%net ); # $VAR1 = { '0' => undef }; 29 | -------------------------------------------------------------------------------- /notes/talks/data_math/Old/L-thoughts_on_the_general_case_in_raku.org: -------------------------------------------------------------------------------- 1 | * Thoughts on doing Data::Math in Raku 2 | ** I haven't gone very far with this yet. 3 | *** tune-in to the next Raku Study Group on June 20th 4 | **** https://www.meetup.com/San-Francisco-Perl/ 5 | ** rummaging around in the toolbox 6 | *** introspection features are built-in 7 | **** perl: "ref", "reftype" 8 | **** raku: .WHAT, .^name, .^mro 9 | *** lookslikenumber => can a string numify? 10 | **** You can just try it, call .Numeric and see if it worked 11 | 12 | #+BEGIN_SRC perl6 13 | if '33333'.Numeric { say 'true!' } else { say 'not.' } # true! 14 | if 'three'.Numeric { say 'true!' } else { say 'not.' } # not. 15 | #+END_SRC 16 | 17 | #+BEGIN_SRC perl6 18 | ## special type that also takes a string that looks like a num 19 | subset Numesque of Any where { defined .Numeric }; 20 | #+END_SRC 21 | *** raku features include operators for zip, reduction, cross products... 22 | -------------------------------------------------------------------------------- /bin/2022aug07/given_with_topic.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # given_with_topic.raku 07 Aug 2022 4 | 5 | use v6; 6 | 7 | 8 | given 32 { 9 | say $_; # 32 10 | } 11 | 12 | 13 | # given 32 { 14 | # $_ = 23; # Cannot assign to an immutable value 15 | # say $_; 16 | # } 17 | 18 | for 32 -> $_ is copy { 19 | $_ = 23; 20 | say $_; # 23 21 | } 22 | 23 | 24 | given 32 -> $_ is copy { 25 | $_ = 23; 26 | say $_; # 23 27 | } 28 | 29 | # Bruce Gray cases: 30 | # raku -e 'my @a = 1, 2; for @a { $_ += 40 }; say @a' 31 | # [41 42] 32 | # raku -e 'my @a = 1, 2; for @a -> $a { $a += 40 }; say @a' 33 | # Cannot assign to a readonly variable or a value 34 | 35 | { 36 | my @a = 1, 2; 37 | for @a { $_ += 40 }; 38 | say @a; # [41 42] 39 | } 40 | 41 | { 42 | my @a = 1, 2; 43 | for @a -> $a { $a += 40 }; # Cannot assign to a readonly variable or a value 44 | say @a 45 | } 46 | -------------------------------------------------------------------------------- /bin/2021apr18/slurpy_array_param.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # slurpy_array_param.raku 18 Apr 2021 4 | 5 | use v6; 6 | 7 | # https://docs.raku.org/type/Signature 8 | 9 | ## colon pair 10 | ## :$a 11 | ## a => $a 12 | 13 | ## Q: whats up with :( ... ) 14 | # $ = :($a, @b); # exactly two arguments, where the second one must be Positional 15 | # $ = :($a, *@b); # at least one argument, @b slurps up any beyond that 16 | # $ = :(*%h); # no positional arguments, but any number of named arguments 17 | 18 | sub one-arg (@) { 19 | 20 | } 21 | 22 | sub slurpy (*@) { 23 | 24 | } 25 | one-arg (5, 6, 7); # ok, same as one-arg((5, 6, 7)) 26 | slurpy (5, 6, 7); # ok 27 | slurpy 5, 6, 7 ; # ok 28 | # one-arg(5, 6, 7) ; # X::TypeCheck::Argument 29 | # one-arg 5, 6, 7 ; # X::TypeCheck::Argument 30 | 31 | sub named-names (*%named-args) { %named-args.keys }; 32 | say named-names :foo(42) :bar; 33 | ## (bar foo) 34 | -------------------------------------------------------------------------------- /bin/2021jun20/elisp_conditionals.el: -------------------------------------------------------------------------------- 1 | ;;; elisp_conditionals.el --- quick demos of cond/if in elisp 2 | 3 | (defun smaller (x y) 4 | "Echo the smaller value" 5 | (let ( smaller ) 6 | (setq smaller 7 | (cond ((< x y) 8 | x) 9 | (t 10 | y))) 11 | (message "smaller: %d" smaller) 12 | )) 13 | 14 | (smaller 3 4) 15 | (smaller 7 2) 16 | 17 | (defun smaller_too (x y) 18 | "Echo the smaller value" 19 | (let ( smaller ) 20 | (cond ((< x y) 21 | (setq smaller x)) 22 | (t 23 | (setq smaller y))) 24 | (message "smaller: %d" smaller) 25 | )) 26 | 27 | (smaller_too 7 13) 28 | (smaller_too 9 3) 29 | 30 | (defun if_smaller (x y) 31 | "Echo the smaller value" 32 | (let ( smaller ) 33 | (setq smaller 34 | (if (< x y) x y)) 35 | (message "smaller: %d" smaller) 36 | )) 37 | 38 | (if_smaller 3 4) 39 | (if_smaller 7 2) 40 | 41 | -------------------------------------------------------------------------------- /bin/2025apr06/deep_and_ducks_and_rows.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # deep_and_ducks_and_rows.raku 06 Apr 2025 4 | 5 | use v6; 6 | 7 | 8 | my @monsters1 = < godzilla mothera ghidora gammera golem rhodan >; 9 | my @monsters2 = < ankou araxxor borrokar damis delrith elvarg kalrag yuri >; ## www.runehq.com 10 | my @monsters3 = < basilisk minotaur behemoth leviathan ziz chimera manticore >; 11 | 12 | my %entities = ( m1 => @monsters1, m2 => @monsters2, m3 => @monsters3 ); 13 | say %entities; 14 | # {m1 => [godzilla mothera ghidora gammera golem rhodan], m2 => [ankou araxxor borrokar damis delrith elvarg kalrag yuri], m3 => [basilisk minotaur behemoth leviathan ziz chimera manticore]} 15 | 16 | my %new = %entities.deepmap( *.uc ); 17 | say %new; 18 | # {m1 => [GODZILLA MOTHERA GHIDORA GAMMERA GOLEM RHODAN], m2 => [ANKOU ARAXXOR BORROKAR DAMIS DELRITH ELVARG KALRAG YURI], m3 => [BASILISK MINOTAUR BEHEMOTH LEVIATHAN ZIZ CHIMERA MANTICORE]} 19 | -------------------------------------------------------------------------------- /bin/2025aug10/ranges_and_sequences_glued_in_array_indexes.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # ranges_and_sequences_glued_in_array_indexes.raku 10 Aug 2025 4 | 5 | use v6; 6 | 7 | { 8 | my @a = 0..50; 9 | say @a[ 3, 5 ... 11, 13..15 ]; 10 | # (3 5 7 9 11 3) 11 | } 12 | 13 | ## Bruce's point: "don't do that" 14 | 15 | 16 | { 17 | my @a = 0..50; 18 | say @a[ 3, (5 ... 11), 13..15 ]; 19 | # (3 (5 6 7 8 9 10 11) (13 14 15)) 20 | } 21 | 22 | 23 | { 24 | my @a = 0..50; 25 | say @a[ 3, 5..11, 13..15 ]; 26 | # (3 (5 6 7 8 9 10 11) (13 14 15)) 27 | } 28 | 29 | 30 | { 31 | ## This example displays almost "normal" behavior, except it skips 12 32 | say 3 ... 7, 11 ... 13; # (3 4 5 6 7 11 13) 33 | say 3 ... 7,11 ... 13; # (3 4 5 6 7 11 13) 34 | 35 | } 36 | 37 | { 38 | # Q: do ranges do better? Yes, except for the formatting glitch: 39 | put 3 .. 7, 11 .. 13; # 3 4 5 6 711 12 13 40 | } 41 | -------------------------------------------------------------------------------- /bin/2025sep07/datetime_37.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # datetime_37.raku 07 Sep 2025 4 | 5 | use v6; 6 | 7 | ## https://www.nntp.perl.org/group/perl.perl6.users/2025/08/msg11493.html 8 | 9 | # raku -e 'my $inst = now; put DateTime.new($inst).local, "\t", DateTime.new($inst.Int).local;' 10 | # 2025-08-28T07:31:01.681240-04:00 2025-08-28T07:31:38-04:00 11 | 12 | { 13 | my $inst = now; 14 | say 15 | DateTime.new($inst).local, "\n", 16 | DateTime.new($inst.Int).local, "\n"; 17 | 18 | # 2025-09-07T16:51:31.888696-07:00 19 | # 2025-09-07T16:52:08-07:00 20 | 21 | # 1:31 22 | # 2:08 23 | 24 | ## yes: 37 seconds difference 25 | } 26 | { 27 | my $inst = now; 28 | say DateTime.new( $inst ).local; 29 | say DateTime.new( $inst.Int ).local; 30 | 31 | say "==="; 32 | my $a = $inst; 33 | my $b = $inst.Int; 34 | say $a - $b; 35 | # Instant:0.523749823 36 | # Hm? 37 | } 38 | -------------------------------------------------------------------------------- /bin/2022dec18/prompt_returns_what.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # prompt_returns_what.raku 18 Dec 2022 4 | 5 | use v6; 6 | 7 | my Int $var; ## must be Int *or any subclass* 8 | 9 | $var = prompt("gimme an int: "); ## Manually type 6 10 | 11 | say $var.WHAT; 12 | say $var; 13 | # (IntStr) 14 | # 6 15 | 16 | say $var.^mro; 17 | # ((IntStr) (Allomorph) (Str) (Int) (Cool) (Any) (Mu)) 18 | say $var.^parents; 19 | # ((Allomorph) (Str) (Int)) 20 | 21 | say "parents tree: "; 22 | say $var.^parents( :tree ); 23 | # parents tree: 24 | # ([(Allomorph) [(Str) [(Cool) [(Any) [(Mu)]]]]] [(Int) [(Cool) [(Any) [(Mu)]]]]) 25 | 26 | say "parents all: "; 27 | say $var.^parents( :all ); 28 | # parents all: 29 | # ((Allomorph) (Str) (Int) (Cool) (Any) (Mu)) 30 | 31 | my Str $var2; 32 | $var2 = prompt("gimme an int: "); ## Manually type 6 33 | say $var2.WHAT; 34 | say $var2; 35 | # gimme an int: 7 36 | # (IntStr) 37 | # 7 38 | 39 | -------------------------------------------------------------------------------- /bin/2022jun05/comma_equals_of_doom.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # comma_equals_of_doom.raku 05 Jun 2022 4 | 5 | use v6; 6 | 7 | 8 | my %model = a => 0, b => 0, c => 0, d => 0; 9 | my %h = b => 1, c => 1; 10 | my %hoh = key => { b => 1, c => 1 }; 11 | my %exp = a => 0, b => 1, c => 1, d => 0; 12 | 13 | 14 | { my %target = %model; 15 | 16 | say ${:b(1), :c(1)}.WHAT; # (Hash) 17 | 18 | %target ,= ${:b(1), :c(1)}.Hash; 19 | say %target; # {a => 0, b => 1, c => 1, d => 0} 20 | } 21 | 22 | 23 | ## Without | you get this error: 24 | ## Odd number of elements found where hash initializer expected: 25 | 26 | { my %target = %model; 27 | say %hoh.WHAT; # (Hash) 28 | say %hoh.elems; # 2 29 | %hoh.kv.say; # (c 1 b 1) 30 | 31 | %target ,= | %hoh; 32 | say %target; # {a => 0, b => 1, c => 1, d => 0} 33 | } 34 | 35 | ## Survey says: deserves to be reported. 36 | 37 | 38 | -------------------------------------------------------------------------------- /bin/2022mar27/hendrix_numbers-01.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # hendrix_numbers-01.raku 25 Mar 2022 4 | 5 | # Programming challenges #1 6 | 7 | # How many Hendrix Numbers are there between 1 and 1000? 8 | # A Hendrix Number is an integer which is invariant when 9 | # all 6s are turned into 9s, and all 9s are turned into 6s. 10 | 11 | # Distinguish between Trivial and True in your answer, 12 | # where Trivial Hendrix Numbers have no 6s or 9s. 13 | 14 | use v6; 15 | 16 | my @trivial; 17 | my @hendrix; 18 | for 1 .. 1000 -> $n { 19 | my $orig = $n; 20 | my $new = $n.Str; 21 | if ( $new ~~ tr/69/96/ ) { 22 | if ( $new.Int == $orig ) { 23 | @hendrix.push( $n ); 24 | } 25 | } else { 26 | @trivial.push( $n ); 27 | } 28 | } 29 | 30 | say "trival: ", @trivial.elems; 31 | say "hendrix: ", @hendrix.elems; 32 | 33 | 34 | # === 35 | # Author: doom@kzsu.stanford.edu 36 | 37 | -------------------------------------------------------------------------------- /bin/2021nov07/junctions_sans_petticoats.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # junctions_sans_petticoats.raku 07 Nov 2021 4 | 5 | use v6; 6 | 7 | my $a = 3; 8 | if $a == 3|4 { 9 | say "truish!"; # truish! 10 | } 11 | 12 | my $COUNT; # GLOBAL 13 | 14 | say dostuff( any(3,7) ); 15 | say dostuff( all(3,7) ); 16 | 17 | # any(True, False) 18 | # all(True, False) 19 | 20 | say so any(True, False); # True 21 | say so all(True, False); # False 22 | 23 | say "COUNT: $COUNT"; # COUNT: 4 24 | # Raku doesn't care if your function has side-effects. Conclusion: watch your back. 25 | 26 | sub dostuff( $arg ) { 27 | $COUNT++; 28 | if $arg <= 5 { 29 | return True; 30 | } else { 31 | return False; 32 | } 33 | } 34 | 35 | 36 | ## 37 | 38 | sub generate_function { 39 | return sub { ... }; 40 | } 41 | my $anonymous_1 = generate_function(); 42 | 43 | 44 | 45 | # === 46 | # Author: doom@kzsu.stanford.edu 47 | 48 | -------------------------------------------------------------------------------- /bin/2023apr30/dummy.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 2023/04/30 20:45:21 3 | 4 | =head1 NAME 5 | 6 | dummy.pl 7 | 8 | =head1 SYNOPSIS 9 | 10 | 11 | =head1 DESCRIPTION 12 | 13 | Stub documentation for dummy.pl, 14 | created by template.el. 15 | 16 | It looks like the author of this script was negligent 17 | enough to leave the stub unedited. 18 | 19 | =cut 20 | 21 | use 5.10.0; 22 | use warnings; 23 | use strict; 24 | $|=1; 25 | use Data::Dumper; 26 | 27 | 28 | sort 29 | 30 | 31 | 32 | __END__ 33 | 34 | =head1 AUTHOR 35 | 36 | Joseph Brenner, Edoom@debian-BULLSEYE-live-builder-AMD64E 37 | 38 | =head1 COPYRIGHT AND LICENSE 39 | 40 | Copyright (C) 2023 by Joseph Brenner 41 | 42 | This program is free software; you can redistribute it and/or modify 43 | it under the same terms as Perl itself, either Perl version 5.10.0 or, 44 | at your option, any later version of Perl 5 you may have available. 45 | 46 | =cut 47 | -------------------------------------------------------------------------------- /bin/2023jul23/collisions_with_unsigiled_containing_callable.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # collisions_with_unsigiled_containing_callable.raku 23 Jul 2023 4 | 5 | use v6; 6 | 7 | { 8 | my \s = 'alpha'; 9 | sub s { 10 | return 'beta'; 11 | } 12 | say s; # alpha 13 | say s(); # beta 14 | } 15 | 16 | { 17 | my \s = 'alpha'; 18 | my sub s { 19 | return 'beta'; 20 | } 21 | say s; # alpha 22 | say s(); # beta 23 | } 24 | 25 | 26 | { 27 | my \s = sub { 'alpha' }; 28 | my sub s { 29 | return 'beta'; 30 | } 31 | say s; # sub { } 32 | say s(); # beta 33 | say s(); # beta 34 | 35 | say "---"; 36 | say s.(); # alpha 37 | } 38 | 39 | say "==="; 40 | { 41 | my sub s { 42 | return 'beta'; 43 | } 44 | 45 | say s(); # beta 46 | 47 | # say s.(); # beta 48 | # ## No such method 'CALL-ME' for invocant of type 'Str' 49 | } 50 | -------------------------------------------------------------------------------- /bin/MultiDispatch/num_types.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # num_types.raku 11 Aug 2024 4 | 5 | use v6; 6 | 7 | 8 | multi ecch (Num $n) { 9 | say "1: we've got a Num type $n"; 10 | } 11 | 12 | multi ecch (Int $n) { 13 | say "Int: we've got an Int type $n"; 14 | } 15 | 16 | multi ecch (Rat $n) { 17 | say "Rat: we've got a Rat type $n"; 18 | } 19 | 20 | multi ecch (Numeric $n) { 21 | say "Numeric: we've got a Numeric type $n"; 22 | } 23 | 24 | multi ecch (Real $n) { 25 | say "Real: we've got a Real type $n"; 26 | } 27 | 28 | ecch( 3 ); # Int: we've got an Int type 3 29 | ecch( 3.3 ); # Rat: we've got a Rat type 3.3 30 | ecch( 3e-3 ); # 1: we've got a Num type 0.003 31 | ecch( 0.003 ); # Rat: we've got a Rat type 0.003 32 | 33 | my Cool $i; 34 | $i = 3e-3; 35 | ecch( $i ); # 1: we've got a Num type 0.003 36 | 37 | ## Conway's Constraint slide: tries rules in order of specifity, so: Int -> Num -> Str 38 | -------------------------------------------------------------------------------- /notes/talks/data_math/D-hash_subtraction_fixed.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | # B5-hash_subtraction_fixed.pl doom@kzsu.stanford.edu 4 | # Jun 08, 2021 5 | 6 | use feature ":5.10.0"; 7 | use warnings; 8 | use strict; 9 | $|=1; 10 | use Data::Dumper; 11 | 12 | { 13 | my (%gross, %costs, %net); 14 | 15 | %gross = ( de => 2345.37, 16 | es => 1238.99, 17 | us => 1.98, 18 | ); 19 | %costs = ( de => 35.00, 20 | es => 259.11, 21 | us => 666.66, 22 | ); 23 | 24 | for my $country ( keys %gross ) { 25 | $net{ $country } = $gross{ $country } - $costs{ $country }; 26 | } 27 | 28 | say Dumper( \%net ); 29 | # $VAR1 = { 30 | # 'us' => '-664.68', 31 | # 'de' => '2310.37', 32 | # 'es' => '979.88' 33 | # }; 34 | 35 | ## So that works fine... right? 36 | 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /bin/2021mar14/find_palindrome_words.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # find_palindromes.raku 12 Mar 2021 4 | 5 | use v6; 6 | 7 | ## I had: 8 | ## for $dict.IO.open( :r ).lines -> $word { 9 | ## but .open is just done implicitly, and read-only is the default 10 | 11 | my $dict = "/usr/share/dict/american-english"; 12 | { 13 | my @words = gather 14 | for $dict.IO.lines -> $word { 15 | if $word ~~ / $($word.flip) / { 16 | take $word if $word.chars > 1; 17 | } 18 | } 19 | 20 | say "count: ", @words.elems; 21 | # find the longest word: 22 | say @words.sort(*.chars).tail; # deified 23 | 24 | say "---"; 25 | # list all in order of length 26 | .say for @words.sort(- *.chars); 27 | } 28 | 29 | 30 | # Observations: 31 | # (1) there are no two character palindrome words, e.g. 'ee' or 'oo'. 32 | # (2) there's no 'zzz' in the dictionary? (one of my favorite words.) 33 | 34 | -------------------------------------------------------------------------------- /bin/2022jun19/controlling_range_of_regex_capture_without_named_regex.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # controlling_range_of_regex_capture_without_named_regex.raku 08 Jul 2022 4 | 5 | use v6; 6 | 7 | # Goal: 8 | # Change a match only when quoted, but leave the quotes in place 9 | 10 | { 11 | 12 | my regex quoted { \" <( <-["]>+ )> \" } 13 | 14 | my $str = q{The "rain" in Spain sprains the brain.}; 15 | say $str ~~ m//; 16 | # 「"rain"」 17 | # quoted => 「rain」 18 | 19 | # try to change the quoted string, but leave quotes alone (NG) 20 | $str ~~ s//refrain/; 21 | say $str; # The refrain in Spain sprains the brain. 22 | # Note: no quotes around refrain 23 | 24 | # try to change the quoted string, but leave quotes alone (NG) 25 | $str ~~ s/ \" <( <-["]>+ )> \" /refrain/; 26 | say $str; # The refrain in Spain sprains the brain. 27 | 28 | 29 | 30 | 31 | say "==="; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /bin/2023jul23/diving_ints_gets_you_type_of.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # diving_ints_gets_you_type_of.raku 23 Jul 2023 4 | 5 | use v6; 6 | 7 | ## Bruce Gray asks the simple question, what type do you get from dividing Ints? 8 | ## Obviously, a Rat. 9 | ## Less obviously, even if it doesn't have to be a Rat? 10 | ## A: Yes, still a Rat. 11 | 12 | ## Output types are determined by input types, not input values. 13 | 14 | { 15 | my $a = 7; 16 | my $b = 5; 17 | my $ratio = $a/$b; 18 | 19 | say $ratio.WHAT; # (Rat) 20 | } 21 | 22 | 23 | { 24 | my $a = 6; 25 | my $b = 3; 26 | my $ratio = $a/$b; 27 | 28 | say $ratio.WHAT; # (Rat) 29 | } 30 | 31 | 32 | { 33 | my $a = 6; 34 | my $b = 3; 35 | my $ratio = $a/$b; 36 | 37 | say $ratio.narrow.WHAT; # (Int) 38 | } 39 | 40 | 41 | { 42 | my $a = 2e0; 43 | say $a.WHAT; # (Num), i.e. a floating point 44 | say $a.narrow.WHAT; # (Int) 45 | } 46 | -------------------------------------------------------------------------------- /notes/talks/new_year_raku/C5-DataMath/D-hash_subtraction_fixed.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | # B5-hash_subtraction_fixed.pl doom@kzsu.stanford.edu 4 | # Jun 08, 2021 5 | 6 | use feature ":5.10.0"; 7 | use warnings; 8 | use strict; 9 | use Data::Dumper; 10 | 11 | { 12 | my (%gross, %costs, %net); 13 | 14 | %gross = ( de => 2345.37, 15 | es => 1238.99, 16 | us => 1.98, 17 | ); 18 | %costs = ( de => 35.00, 19 | es => 259.11, 20 | us => 666.66, 21 | ); 22 | 23 | for my $country ( keys %gross ) { 24 | $net{ $country } = $gross{ $country } - $costs{ $country }; 25 | } 26 | 27 | say Dumper( \%net ); 28 | # $VAR1 = { 29 | # 'us' => '-664.68', 30 | # 'de' => '2310.37', 31 | # 'es' => '979.88' 32 | # }; 33 | 34 | ## So that works fine... right? 35 | 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /notes/talks/data_math/F-hash_subtraction_via_Data-Math.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # F-hash_subtraction_via_Data-Math.pl doom@kzsu.stanford.edu 3 | # June 08, 2021 4 | 5 | use feature ":5.10.0"; 6 | use warnings; 7 | use strict; 8 | $|=1; 9 | use Data::Dumper; 10 | use Data::Math; 11 | 12 | { 13 | my ( %gross, %costs ); 14 | %gross = ( de => 2345.37, 15 | es => 1238.99, 16 | us => 1.98, 17 | ); 18 | %costs = ( de => 35.00, 19 | es => 259.11, 20 | us => 666.66, 21 | fr => 101.01, 22 | ); 23 | 24 | my $dm = Data::Math->new(); 25 | my $net = $dm->calc( '-', \%gross, \%costs ); 26 | 27 | say Dumper( $net ); 28 | # $VAR1 = { 29 | # 'fr' => '-101.01', 30 | # 'de' => '2310.37', 31 | # 'us' => '-664.68', 32 | # 'es' => '979.88' 33 | # }; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /bin/2022apr10/bills_so_yaml_key_fusion.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # bills_so_yaml_key_fusion.raku 10 Apr 2022 4 | 5 | # https://unix.stackexchange.com/questions/696495/find-duplicate-1st-field-and-concat-its-values-in-single-line/698487#698487 6 | 7 | use v6; 8 | 9 | ## kinda sorta yaml 10 | my $df = "/home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2022apr10/dat/so.dat"; 11 | 12 | { 13 | my %h; 14 | for $df.IO.lines() { 15 | %h .= append: .split(":").map( *.trim ).hash 16 | }; 17 | .say for %h.sort; 18 | } 19 | say "\n===\n"; 20 | { 21 | my %h .= append: .split(":").map(*.trim).hash for $df.IO.lines; 22 | .say for %h.sort; 23 | } 24 | 25 | say "\n===\n"; 26 | { 27 | .say for sort $df.IO.lines().map( *.split(":",2)).classify({.[0]}, :as{.[1]} ); 28 | } 29 | 30 | say "\n===\n"; 31 | { 32 | .say for sort $df.IO.lines().map( { /^(\S+)\:\s*\x27(.+?)\x27$/ or die; ~$0, ~$1 } ).classify( {.[0]}, :as{.[1]} ); 33 | } 34 | -------------------------------------------------------------------------------- /bin/2024oct20/calculations_assigned_to_rats_and_fatrats.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # calculations_assigned_to_rats_and_fatrats.raku 24 Nov 2024 4 | 5 | use v6; 6 | 7 | # one past the limit for Rat demoninators 8 | my $d = 2**64 + 1; 9 | 10 | # Rat.new allows for toofat Rats that aren't FatRats 11 | my $rat = Rat.new(1, $d); ## doesn't throw an error, and gives you a Rat, not a Num 12 | say $rat.^name, ': ', $rat, ' '; 13 | 14 | # ## my Rat $v_r = 1/$d; ## Type check failed in assignment to $v_r; expected Rat but got Num (5.421010862427522e-20) 15 | # my FatRat $v_fr = 1/$d; 16 | # my Num $v_n = 1/$d; 17 | 18 | # ## say $v_r.^name, ': ', $v_r, ' '; 19 | # say $v_fr.^name, ': ', $v_fr, ' '; 20 | # say $v_n.^name, ': ', $v_n, ' '; 21 | 22 | 23 | { 24 | my $rat = Rat.new(1, $d); ## doesn't throw an error, and gives you a Rat, not a Num 25 | say $rat.^name, ': ', $rat, ' '; 26 | 27 | my $result = $rat * 1/2; 28 | dd( $result ); 29 | } 30 | -------------------------------------------------------------------------------- /bin/the_dreaded_leland_number_golf_castrophe.pl6: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # the_dreaded_leland_number_golf_castrophe.pl6 11 Oct 2020 4 | 5 | 6 | use v6; 7 | 8 | # Related to this: 9 | # https://www.nntp.perl.org/group/perl.perl6.users/2020/10/msg9278.html 10 | 11 | # bruce gray example: 12 | # 13 | # say 2..4 X[&({$^a**$^b+$b**$a})] 2..4; 14 | 15 | say 2..4 X[&({$^a**$^b+$b**$a})] 2..4; 16 | # (8 17 32 17 54 145 32 145 512) 17 | 18 | # my reformatting for readability: 19 | say 2..4 X[&( { $^a ** $^b + $b ** $a } )] 2..4; 20 | (8 17 32 17 54 145 32 145 512) 21 | 22 | # Note: 23 | # a space *after* the X[ confuses things: "Missing infix inside []" 24 | # say 2..4 X[ &( { $^a ** $^b + $b ** $a } ) ] 2..4; 25 | 26 | 27 | # Anyway, what struck me there was that after $^a you can get the value with just: $a. 28 | # That makes the code tighter, but it looks pretty weird the first time you see it, 29 | # and I don't think I've ever seen it before. 30 | 31 | -------------------------------------------------------------------------------- /notes/meeting_2022dec04.org: -------------------------------------------------------------------------------- 1 | * meeting notes December 05, 2022 2 | ** the raku study group 3 | **** usual links 4 | ***** these notes 5 | ****** https://github.com/doomvox/raku-study/blob/main/notes/meeting_2022dec04.md 6 | ****** source file (for corrections, etc) 7 | ******* https://github.com/doomvox/raku-study/blob/main/notes/meeting_2022dec04.org 8 | ***** code examples 9 | ****** https://github.com/doomvox/raku-study/tree/main/bin/2022dec04 10 | ***** last meeting notes 11 | ****** https://github.com/doomvox/raku-study/blob/main/notes/meeting_2022nov20.md 12 | 13 | 14 | ** topics 15 | 16 | *** https://github.com/PerlMonk-Athanasius/perlweeklychallenge-club/blob/branch-for-challenge-191/challenge-191/athanasius/raku/ch-1.raku#L119 17 | **** still need to cover Bruce Gray's solution. 18 | 19 | ** announcements 20 | *** lambert lum is looking for raku speakers for svperl on Jan 5, 2023 21 | 22 | *** December 11th: the next raku study group meeting, in 2 weeks as usual 23 | -------------------------------------------------------------------------------- /bin/2021aug29/so_question_order_of_operations_with_R_and_pop.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # so_question_pop_orders.raku 29 Aug 2021 4 | 5 | use v6; 6 | 7 | ## https://stackoverflow.com/questions/68761964/raku-pop-order-of-execution 8 | 9 | ## Minor puzzle with the R (reverse) feature: 10 | ## doesn't just reverse the operation, 11 | ## it reverses the order of evalation of the operands. 12 | 13 | { 14 | my @a = my @b = [9 , 3]; 15 | say ( @a[1] - @a[0] ) == ( @b[1] R- @b[0] ); # False {as expected} 16 | say ( @a.pop() - @a.pop() ) == ( @b.pop() R- @b.pop() ); # True {Huh?!?} 17 | } 18 | 19 | { 20 | say 3 - 2; # 1 21 | say 3 R- 2; # -1 22 | say 2 R- 3; # 1 23 | } 24 | 25 | { 26 | say "---"; 27 | my @a = my @b = [9 , 3]; 28 | say @a.pop; # 3 29 | say @a.pop; # 9 30 | say @b.pop; # 3 31 | say @b.pop; # 9 32 | } 33 | 34 | 35 | 36 | 37 | # === 38 | # Author: doom@kzsu.stanford.edu 39 | 40 | -------------------------------------------------------------------------------- /bin/2022sep25/smartmaching_arrays_lists.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # smartmaching_arrays_lists.raku 25 Sep 2022 4 | 5 | use v6; 6 | 7 | my @a = 1, 2, 3; 8 | say @a; # [1 2 3] 9 | 10 | say so @a eqv (1, 2, 3); 11 | # False 12 | 13 | say so @a ~~ (1, 2, 3); 14 | # True 15 | 16 | 17 | my @a = < alpha beta gamma >; 18 | my @c = < whun tew thuree >; 19 | my @b = < godzilla mothera rhodan >; 20 | 21 | my $d = [ 'perl', 'raku', ]; 22 | say $d.WHAT; # (Array) 23 | say $d; # [perl raku] 24 | 25 | my @array_of_arefs = ( @a, @b, @c, $d, @a, @b ); 26 | 27 | say @array_of_arefs; 28 | # [[alpha beta gamma] [godzilla mothera rhodan] [whun tew thuree] [perl raku] [alpha beta gamma] [godzilla mothera rhodan]] 29 | 30 | my @result = 31 | @array_of_arefs.unique(with => &[eqv]); 32 | 33 | say @result; 34 | # [[alpha beta gamma] [godzilla mothera rhodan] [whun tew thuree] [perl raku]] 35 | 36 | ## So, eqv does the job in raku... 37 | ## though: what's an "arrayref"? 38 | -------------------------------------------------------------------------------- /bin/2023dec03/mkdir.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env raku 2 | # 3 | # mkdir.raku 30 Nov 2023 4 | 5 | use v6; 6 | 7 | ## Checking that with Raku's "mkdir", it does not complain if the directory exists already. 8 | my $t = "/home/doom/tmp/YetAnotherDamnTestLocationToMessWith"; 9 | { 10 | my $io_path_obj = mkdir( $t ); 11 | dd( $io_path_obj ); 12 | } 13 | say "==="; 14 | { 15 | say "Let's try that again..."; 16 | my $io_path_obj = mkdir( $t ); 17 | dd( $io_path_obj ); 18 | } 19 | say "==="; 20 | 21 | my $file = "/home/doom/tmp/Alpha/Widget"; 22 | spurt( $file ); # create $file without text, like touch 23 | mkdir( $file ); 24 | 25 | # Failed to create directory '/home/doom/tmp/Alpha/Widget' with mode '0o777': Failed to mkdir: File exists 26 | # in block at /home/doom/End/Cave/RakuStudy/Wall/raku-study/bin/2023dec03/mkdir.raku line 23 27 | 28 | 29 | ## Usual use of "spurt": 30 | ## $file.IO.spurt( $text ); 31 | 32 | 33 | ## perl5 34 | ## mkdir( $d ) unless -d $d; 35 | -------------------------------------------------------------------------------- /bin/2021may30/crossproduct_operator_slash_x_etc.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # crossproduct_operator_slash_x_etc.raku 30 May 2021 4 | 5 | use v6; 6 | 7 | ## looking at bruce gray's solution: 8 | ## http://rosettacode.org/wiki/Sum_of_first_n_cubes 9 | 10 | ## playing with the operators used there: 11 | 12 | my @n = 1, 2, 3, 4, 5, 6; 13 | 14 | 15 | say [+] @n; # 21 16 | say [\+] @n; # (1 3 6 10 15 21) 17 | 18 | # "triangle operator" 19 | # "produce" (triangular reduction) 20 | 21 | say 1 + 2; 22 | # say 1 \+ 2; 23 | 24 | say X~ <1 2 3>; 25 | # (A1 A2 A3 B1 B2 B3 C1 C2 C3) 26 | 27 | say X~ 0; 28 | # (A0 B0 C0) 29 | 30 | say (1, 3, 5) X+ 1; 31 | # (2 4 6) 32 | 33 | say (1, 3, 5) X+ (10, 20, 30); 34 | # (11 21 31 13 23 33 15 25 35) 35 | 36 | say @n X** 2; 37 | # (1 4 9 16 25 36) 38 | 39 | say @n X** 3; 40 | # (1 8 27 64 125 216) 41 | 42 | say (1,3,5) >>**>> 4; ## parallelizable 43 | # (1 81 625) 44 | 45 | say (1,3,5) X** 4; 46 | # (1 81 625) 47 | 48 | -------------------------------------------------------------------------------- /bin/2021mar21/parsing_quoted_strings_backslash.raku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl6 2 | # 3 | # parsing_quoted_strings.raku 21 Mar 2021 4 | 5 | use v6; 6 | 7 | ## Make errors into warnings 8 | ## CATCH { default { say "CAUGHT: ", .Str; .resume } } 9 | 10 | my $txt = q:to/END_TXT/; 11 | Here we have a "quoted" string. 12 | END_TXT 13 | 14 | my $txt2 = q:to/END_TXT/; 15 | Here we nested quotes: "quotes can be \"scary\" yes" string. 16 | END_TXT 17 | 18 | # p.80 moritz lenz 'parsing' 19 | { 20 | my regex quote { 21 | \" 22 | [ 23 | <-[ " \\ ]> ## regular character 24 | | \\ . ## escape sequence 25 | ]* 26 | \" 27 | }; 28 | 29 | $txt ~~ m//; 30 | say $/; 31 | 32 | # 「"quoted"」 33 | # quote => 「"quoted"」 34 | 35 | say $; # 「"quoted"」 36 | 37 | $txt2 ~~ m//; 38 | say $/; 39 | # 「"quotes can be \"scary\" yes"」 40 | # quote => 「"quotes can be \"scary\" yes"」 41 | 42 | } 43 | 44 | --------------------------------------------------------------------------------