more instructions

This commit is contained in:
Rowan Torbitzky-Lane 2025-01-24 01:38:54 -06:00
parent 452e7a2b49
commit de8fedb5d1
2 changed files with 32 additions and 0 deletions

View File

@ -108,3 +108,18 @@ instructionShoveDup state@(State {_int = []}) _ = state
-- also also not int generic
instructionShove :: State -> Lens' State [a] -> State
instructionShove state accessor = instructionShoveDup state accessor & accessor .~ drop 1 (view accessor (instructionShoveDup state accessor))
-- not char generic
instructionConcat :: Semigroup a => State -> Lens' State [a] -> State
instructionConcat state accessor =
if (length . take 2 $ view accessor state) == 2
then droppedState & accessor .~ (head (view accessor state) <> view accessor state !! 1) : view accessor droppedState
-- then undefined
else state
where
droppedState :: State
droppedState = state & accessor .~ drop 2 (view accessor state)
-- evolve fodder???????????
instructionNoOp :: State -> State
instructionNoOp state = state

View File

@ -0,0 +1,17 @@
module Instructions.StringInstructions where
import State
import Instructions.GenericInstructions
combineString :: String -> (String, String) -> String
combineString toInsert (front, back) = front <> toInsert <> back
instructionStringConcat :: State -> State
instructionStringConcat state = instructionConcat state string
instructionStringSwap :: State -> State
instructionStringSwap state = instructionSwap state string
instructionStringInsertString :: State -> State
instructionStringInsertString state@(State{_string = s1 : s2 : ss, _int = i1 : is}) = state {_string = combineString s2 (splitAt i1 s1) : ss, _int = is}
instructionStringInsertString state = state