自己先写了一个单链表

mutable struct ListElmt{T}
value::T
next::Union{Nothing,ListElmt}
end

mutable struct List
size::Int
head::Union{Nothing,ListElmt}
tail::Union{Nothing,ListElmt}

ins_pos::Int

end

#--------init--------#
List()=List(0,nothing,nothing)
ListElmt(data)=ListElmt(data,nothing)
#--------init--------#

#--------macro----------#

macro list_size(list)
:($(list).size)
end

macro list_head(list)
:($(list).head)
end

macro list_tail(list)
:($(list).tail)
end

macro list_next(elmt)
:($(elmt).next)
end

macro list_data(elmt)
:($(elmt).value)
end
#--------macro----------#

#--------function---------#
function push(list::List,data)
new_elmt=ListElmt(data)
if list.size==0
list.head=list.tail=new_elmt
else
list.tail=list.tail.next=new_elmt
end
list.size+=1
end

function remove(list::List)
if list.size==0
return nothing
else
current=list.head
for i=1:list.size-2
current=current.next
end
res=current.next.value
list.tail=current
list.size-=1
return res
end
end

function show(list::List)
current=list.head
for i in 1:list.size
print(current.value," ")
current=current.next
end
println()
end

function contain(list::List,data)
current=list.head
while current != nothing
if data==current.value
return true
end
current=current.next
end
return false
end

#--------function---------#

另外发现一点小问题,在函数内竟然不能用宏
list-push

发现的错误:

可以保证的是不在函数内用宏是没有问题的

说明一下,不要在意那个List里的ins_pos,本来想让List,Stack,Queue都派生自抽象类AbstractList的,不过方案还没想好,有望改进

请不要这样用宏,这不仅会给编译器增加负担,而且导致syntax很不统一。如果你要取成员可以直接用函数。

再说一次,请在你的帖子里使用markdown的code block发帖子。此外你没有重载Base的函数接口。这里没有type privacy的问题,你这样做会导致大量的重复代码。

如果我用函数这样写,那么返回的成员是按传值返回的,不能修改


这是用我的方法

这是你的方法
确实有很大区别

请阅读文档:类型 · Julia中文文档

这是非常基础的Julia语法,个人建议你阅读文档或者先寻找其它学习资料学习Julia语法。