update instructions list/formatting

This commit is contained in:
Rowan Torbitzky-Lane 2025-02-11 17:05:16 -06:00
parent 899aaa93a7
commit 84e5c7b1df
7 changed files with 685 additions and 529 deletions

View File

@ -15,7 +15,7 @@ test: # Runs unit tests.
runghc -i./src/ test/Main.hs runghc -i./src/ test/Main.hs
format: # Formats code using ormolu. format: # Formats code using ormolu.
ormolu --mode inplace app/*.hs src/*.hs test/*.hs ormolu --mode inplace app/*.hs src/HushGP/*.hs test/*.hs
hlint: # HLint for lint suggestions. hlint: # HLint for lint suggestions.
hlint src/*.hs hlint src/*.hs

View File

@ -13,7 +13,7 @@
- [X] Write haddock documentation for each function - [X] Write haddock documentation for each function
- [X] Refactor all functions to take state as the final parameter - [X] Refactor all functions to take state as the final parameter
- [X] Standardize the pattern matching parameter names, such as c1 : cs - [X] Standardize the pattern matching parameter names, such as c1 : cs
- [ ] Write unit/quickcheck tests for all of the instructions - [ ] Write unit/quickcheck tests for the generic functions
~~[ ] Use template haskell to generate function lists~~ ~~[ ] Use template haskell to generate function lists~~
- [X] Move utility functions to their own file - [X] Move utility functions to their own file
- [ ] Make add/sub/mult/div/mod instructions generic - [ ] Make add/sub/mult/div/mod instructions generic

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,6 @@ module HushGP.Instructions.StringInstructions where
import HushGP.State import HushGP.State
import HushGP.Instructions.GenericInstructions import HushGP.Instructions.GenericInstructions
import HushGP.Instructions.Utility import HushGP.Instructions.Utility
import Control.Lens
-- |Concats the top two strings on the string stack and pushes the result. -- |Concats the top two strings on the string stack and pushes the result.
instructionStringConcat :: State -> State instructionStringConcat :: State -> State
@ -221,14 +220,6 @@ instructionStringStripWhitespace :: State -> State
instructionStringStripWhitespace state@(State {_string = s1 : ss}) = state{_string = strip s1 : ss} instructionStringStripWhitespace state@(State {_string = s1 : ss}) = state{_string = strip s1 : ss}
instructionStringStripWhitespace state = state instructionStringStripWhitespace state = state
-- |Utility Function: Casts a type based on a lens to a string. Pushes the result
-- to the string stack.
instructionStringFromLens :: Show a => Lens' State [a] -> State -> State
instructionStringFromLens accessor state@(State {_string = ss}) =
case uncons (view accessor state) of
Nothing -> state
Just (x1,_) -> state{_string = show x1 : ss}
-- |Converts the top bool from the bool stack to a string. Pushes the result to -- |Converts the top bool from the bool stack to a string. Pushes the result to
-- the string stack. -- the string stack.
instructionStringFromBool :: State -> State instructionStringFromBool :: State -> State

View File

@ -247,3 +247,13 @@ lstrip s = case s of
-- this is a tad inefficient -- this is a tad inefficient
rstrip :: String -> String rstrip :: String -> String
rstrip = reverse . lstrip . reverse rstrip = reverse . lstrip . reverse
-- string utility
-- |Utility Function: Casts a type based on a lens to a string. Pushes the result
-- to the string stack.
instructionStringFromLens :: Show a => Lens' State [a] -> State -> State
instructionStringFromLens accessor state@(State {_string = ss}) =
case uncons (view accessor state) of
Nothing -> state
Just (x1,_) -> state{_string = show x1 : ss}