Add O(1) cons/uncons

This commit is contained in:
Alwinfy 2022-05-08 15:57:22 -04:00 committed by yrsegal@gmail.com
parent f893fe2a69
commit 6d4434fed6
5 changed files with 61 additions and 0 deletions

View file

@ -450,6 +450,10 @@ public class RegisterPatterns {
OpSlice.INSTANCE); OpSlice.INSTANCE);
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("wqaeaqw", HexDir.NORTH_WEST), modLoc("modify_in_place"), PatternRegistry.mapPattern(HexPattern.FromAnglesSig("wqaeaqw", HexDir.NORTH_WEST), modLoc("modify_in_place"),
OpModifyInPlace.INSTANCE); OpModifyInPlace.INSTANCE);
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("ddewedd", HexDir.SOUTH_EAST), modLoc("construct"),
OpCons.INSTANCE);
PatternRegistry.mapPattern(HexPattern.FromAnglesSig("aaqwqaa", HexDir.SOUTH_WEST), modLoc("deconstruct"),
OpUnCons.INSTANCE);
} catch (PatternRegistry.RegisterPatternException exn) { } catch (PatternRegistry.RegisterPatternException exn) {
exn.printStackTrace(); exn.printStackTrace();

View file

@ -0,0 +1,17 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpCons : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val bottom = args.getChecked<SpellList>(0)
val top = args[1]
return spellListOf(SpellList.LPair(top, bottom))
}
}

View file

@ -0,0 +1,20 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpUnCons : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val list = args.getChecked<SpellList>(0)
if (list.nonEmpty) {
return spellListOf(list.cdr, list.car)
}
return spellListOf(list, Widget.NULL)
}
}

View file

@ -200,6 +200,8 @@
"hexcasting.spell.hexcasting:list_remove": "Excisor's Distillation", "hexcasting.spell.hexcasting:list_remove": "Excisor's Distillation",
"hexcasting.spell.hexcasting:slice": "Selection Exaltation", "hexcasting.spell.hexcasting:slice": "Selection Exaltation",
"hexcasting.spell.hexcasting:modify_in_place": "Surgeon's Exaltation", "hexcasting.spell.hexcasting:modify_in_place": "Surgeon's Exaltation",
"hexcasting.spell.hexcasting:construct": "Speaker's Distillation",
"hexcasting.spell.hexcasting:deconstruct": "Speaker's Decomposition",
"hexcasting.spell.hexcasting:get_entity": "Entity Purification", "hexcasting.spell.hexcasting:get_entity": "Entity Purification",
"hexcasting.spell.hexcasting:get_entity/animal": "Entity Prfn.: Animal", "hexcasting.spell.hexcasting:get_entity/animal": "Entity Prfn.: Animal",
"hexcasting.spell.hexcasting:get_entity/monster": "Entity Prfn.: Monster", "hexcasting.spell.hexcasting:get_entity/monster": "Entity Prfn.: Monster",
@ -808,6 +810,8 @@
"hexcasting.page.lists.index_of": "Remove the iota at the top of the stack, then replace the list at the top with the first index of that iota within the list (starting from 0). Replaces the list with -1 if the iota doesn't exist in the list.", "hexcasting.page.lists.index_of": "Remove the iota at the top of the stack, then replace the list at the top with the first index of that iota within the list (starting from 0). Replaces the list with -1 if the iota doesn't exist in the list.",
"hexcasting.page.lists.list_remove": "Remove the number at the top of the stack, then remove the nth element of the list at the top of the stack (where n is the number you removed).", "hexcasting.page.lists.list_remove": "Remove the number at the top of the stack, then remove the nth element of the list at the top of the stack (where n is the number you removed).",
"hexcasting.page.lists.modify_in_place": "Remove the top iota of the stack and the number at the top, then set the nth element of the list at the top of the stack to that iota (where n is the number you removed). Does nothing if the number is out of bounds.", "hexcasting.page.lists.modify_in_place": "Remove the top iota of the stack and the number at the top, then set the nth element of the list at the top of the stack to that iota (where n is the number you removed). Does nothing if the number is out of bounds.",
"hexcasting.page.lists.construct": "Remove the top iota, then add it as the first element to the list at the top of the stack.",
"hexcasting.page.lists.deconstruct": "Remove the first iota from the list at the top of the stack, then push that iota to the stack.",
"hexcasting.entry.patterns_as_iotas": "Patterns as Iotas", "hexcasting.entry.patterns_as_iotas": "Patterns as Iotas",
"hexcasting.page.patterns_as_iotas.1": "One of the many peculiarities of this art is that $(italic)patterns themselves/$ can act as iotas-- I can even put them onto my stack when casting.$(br2)This raises a fairly obvious question: how do I express them? If I simply drew a pattern, it would hardly tell Nature to add it to my stack-- rather, it would simply be matched to an action.", "hexcasting.page.patterns_as_iotas.1": "One of the many peculiarities of this art is that $(italic)patterns themselves/$ can act as iotas-- I can even put them onto my stack when casting.$(br2)This raises a fairly obvious question: how do I express them? If I simply drew a pattern, it would hardly tell Nature to add it to my stack-- rather, it would simply be matched to an action.",

View file

@ -93,6 +93,22 @@
"input": "list, num, any", "input": "list, num, any",
"output": "list", "output": "list",
"text": "hexcasting.page.lists.modify_in_place" "text": "hexcasting.page.lists.modify_in_place"
},
{
"type": "hexcasting:pattern",
"op_id": "hexcasting:construct",
"anchor": "hexcasting:construct",
"input": "list, any",
"output": "list",
"text": "hexcasting.page.lists.construct"
},
{
"type": "hexcasting:pattern",
"op_id": "hexcasting:deconstruct",
"anchor": "hexcasting:deconstruct",
"input": "list",
"output": "list, any",
"text": "hexcasting.page.lists.deconstruct"
} }
] ]
} }