<commit_before>{-# LANGUAGE QuasiQuotes #-}
module Atomo.Kernel.String where

import Data.List (sort)
import qualified Data.Text as T

import Atomo


load :: VM ()
load = do
    [$p|(s: String) as: List|] =:
        liftM (list . map Char) (getString [$e|s|])

    [$p|(l: List) to-string|] =: do
        vs <- getList [$e|l|]

        if all isChar vs
            then return $ string (map (\(Char c) -> c) vs)
            else raise' "list-not-homogenous"

    [$p|(c: Char) singleton|] =: do
        Char c <- here "c" >>= findChar
        return (String (T.singleton c))

    [$p|(s: String) length|] =:<commit_msg>Moved @(String as: _) from Kernel.hs and added @(String as: Rational)<commit_after>{-# LANGUAGE QuasiQuotes #-}
module Atomo.Kernel.String where

import Data.List (sort)
import qualified Data.Text as T

import Atomo


load :: VM ()
load = do
    [$p|(s: String) as: List|] =:
        liftM (list . map Char) (getString [$e|s|])

    [$p|(s: String) as: Char|] =: do
        s <- getString [$e|s|]
        return (Char (head s))
    
    [$p|(s: String) as: Integer|] =: do
        s <- getString [$e|s|]
        return (Integer (read s))
        
    [$p|(s: String) as: Double|] =: do
        s <- getString [$e|s|]
        return (Double (read s))
    
    [$p|(s: String) as: Rational|] =: do
        s <- getString [$e|s|]
        let num = read $ takeWhile (/= '/') s
            denom = read . tail $ dropWhile (/= '/') s
        return (Rational (num % denom))

    [$p|(l: List) to-string|] =: do
        vs <- getList [$e|l|]

        if all isChar vs
            then return $ string (map (\(Char c) -> c) vs)
            else raise' "list-not-homogenous"

    [$p|(c: Char) singleton|] =: do
        Char c <- here "c" >>= findChar
        return (String (T.singleton c))

    [$p|(s: String) length|] =:
{'fraction_non_alphanumeric': 0.17938931297709923, 'fraction_numerical': 0.0, 'mean_word_length': 2.1367521367521367, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '893917', 'n_tokens_mistral': 705, 'n_tokens_neox': 660, 'n_words': 203}