@wisaaco Can you run something like swipl --version on your machine? This is what I see:
$ swipl --version
SWI-Prolog version 8.1.17 for x86_64-linux
It might be that your installation is somehow botched. It is also not clear at all how you load the code, how you run it and so on. If I put your code in a file called foo.pl, I for example get the following:
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.17-8-g2276d5765)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- [foo].
Warning: foo.pl:8:
Warning: Local definition of user:last/2 overrides weak import from lists
Warning: foo.pl:19:
Warning: Singleton variables: [M]
true.
?- action(n1, M).
false.
in other words, you have all kinds of other problems and it isn’t even clear what you are doing.